В следующем примере показано, как выполнить какое-либо действие в другом потоке, а не в потоке пользовательского интерфейса. Я не знаю много о COM, поэтому я не могу сказать, как это сочетается с COM-вызовами, но для стороны .net это должно помочь вам, не читая много. Здесь вы найдете документацию.
BackgroundWorker bgWorker = new BackgroundWorker() { WorkerReportsProgress=true};
bgWorker.DoWork += (s, e) => {
// As your requested, here an example on how you yould instantiate your working class,
// registering to some progresse event and relay the progress to the backgorund-worker:
YourClass workingInstance=new YourClass();
workingInstance.WorkProgress+=(o,yourProgressEvent)=>{
bgWorker.ReportProgress(yourProgressEvent.ProgressPercentage);
};
workingInstance.Execute();
};
bgWorker.ProgressChanged+=(s,e)=>{
// Here you will be informed about progress and here it is save to change/show progress.
// You can access from here savely a ProgressBars or another control.
};
bgWorker.RunWorkerCompleted += (s, e) => {
// Here you will be informed if the job is done.
// Use this event to unlock your gui
};
bgWorker.RunWorkerAsync();
Хотя я не рекомендую использовать его, вот пример кода, который делает что-то похожее на то, что вы знаете из DoEvents:
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object parameter) {
frame.Continue = false;
return null;
}), null);
Dispatcher.PushFrame(frame);