2011-05-24 49 views
0

ProgressForm是一個表單。 我想在ProccessingReport方法執行完成時執行某些操作。作業完成時如何做某事(IAsyncResult)

IAsyncResult AsyncResult = ProgressForm.BeginInvoke(new Action(ProcessingReport)); 

現在我做這樣的事情:

while (!AsyncResult.IsCompleted) 
    { 
     Application.DoEvents(); 
    } 
    doSomething(); 

我不能移動DoSomething的()操作ProcessingReport方法。有可能嗎?謝謝。

+0

@LightWing:你有沒有考慮使用[BackgroundWorker](http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx)? – 2011-05-24 09:12:50

+0

不,我不想使用BackgroundWorker.But,如果我必須使用BackgroundWorker來做,所以我會。 – Saleh 2011-05-24 09:14:26

+1

舉辦活動吧?或發送一個回調委託? – Magnus 2011-05-24 09:15:09

回答

1

創建DoAsyncProcessingReportResult方法,它的參數,如:

private void DoAsyncProcessingReportResult(IAsyncResult iar) 
{ 
    AsyncResult ar = (AsyncResult)iar; 
    // map this to your delegate (take mine as an example) 
    Func<RemoteDirectoryInfo> LoadProcessingReport = 
      (Func<RemoteDirectoryInfo>)ar.AsyncDelegate; 

    // Then get your answer from calling the EndInvoke 
    _Directory = LoadProcessingReport.EndInvoke(ar); 
} 

你叫ProcessingReport(以煤礦爲例)

Func<RemoteDirectoryInfo> LoadProcessingReport = ProcessingReport; 
LoadProcessingReport.BeginInvoke(DoAsyncProcessingReportResult, null); 

我修改了代碼,以反映你的最好的,我可以決定。您必須修復委託聲明以適合您的代碼。