【发布时间】:2012-03-06 03:35:28
【问题描述】:
我注意到保存和释放 MailItem 是一项耗时的任务。那么,执行以下操作是否安全? (下面是伪代码)
Thread 1 (main thread)
- Open 10 (different .msg files) - MailItems [List<MailItem> items]
- user works on them and want to save and close all of them with one click.
- On_save_All_click (runs on main thread)
- Do
- toBeClearedList.addAll(items);
- items.clear() [so that main thread cannot access those items]
- BG_Thread.ExecuteAsyn(toBeClearedList);
- End
Thread 2 (background thread) (input - List<MailItems>)
- foreach(MailItem item in input)
item.save();
System.Runtime.InteropServices.Marshal.ReleaseComObject(item)
- done
我写了几个测试,看起来它工作正常;只是想知道这样做是否安全? “在与创建它的线程不同的线程中释放 COM 对象”
谢谢
卡雷菲尔
【问题讨论】: