开发者

How to do something when a job finished (IAsyncResult)

ProgressForm is a Form. I want to do something when the ProccessingReport met开发者_Go百科hod execution finished.

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

Now I do something like this :

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

I can't move the doSomething() operation to ProcessingReport method. Is it possible?Thanks.


Create a DoAsyncProcessingReportResult method that takes a parameter like:

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);
}

You call ProcessingReport (taking mine as an example)

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

I modified my code to reflect yours the best I could determine. You'll have to fix the delegate declaration to fit your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜