这是Microsoft的代码片段.我对异步方法调用有疑问.
因为我们正在调用end.Invoke在Begin-invoke之后看起来我们正在进行同步调用.因为我们正在等待异步调用的返回值.
如果异步方法在调用end.invoke时没有完成,会发生什么.我们可以继续下一个声明,或者我们必须等待.
如果在多线程环境中发生这种情况,它们如何处理回调信号以纠正线程.
public void DemoEndInvoke()
{
MethodDelegate dlgt = new MethodDelegate (this.LongRunningMethod) ;
string s ;
int iExecThread;
// Initiate the asynchronous call.
IAsyncResult ar = dlgt.BeginInvoke(3000, out iExecThread, null, null);
// Do some useful work here. This would be work you want to have
// run at the same time as the asynchronous call.
// Retrieve the results of the asynchronous call.
s = dlgt.EndInvoke (out iExecThread, ar) ;
MessageBox.Show (string.Format ("The delegate call returned the string: …
Run Code Online (Sandbox Code Playgroud)