异步调用Web服务,执行WaitAll出错
Jelon 2003-08-05 09:22:53 在vs.net2003中运行以下代码:
localhost2.SleepService1 cServiceA=new Chapter19CSharpClient.localhost2.SleepService1();
localhost.SleepService2 cServiceB=new Chapter19CSharpClient.localhost.SleepService2();
IAsyncResult arA=cServiceA.BeginSleepServiceA(100,null,null);
IAsyncResult arB=cServiceB.BeginSleepServiceB(1000,null,null);
WaitHandle[] wh={arA.AsyncWaitHandle,arB.AsyncWaitHandle};
//WaitHandle[] wh={arB.AsyncWaitHandle};
WaitHandle.WaitAll(wh);
txtResult.Text=cServiceA.EndSleepServiceA(arA);
txtResult.Text+="\r\n"+cServiceB.EndSleepServiceB(arB);
执行到WaitHandle.WaitAll(wh);时出错,出错信息:
未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。
其他信息: 不支持一个 STA 线程上多个句柄的 WaitAll。
而将WaitHandle[] wh={arA.AsyncWaitHandle,arB.AsyncWaitHandle};
替换为WaitHandle[] wh={arA.AsyncWaitHandle};或WaitHandle[] wh={arB.AsyncWaitHandle};时,均可正常运行。
请各位高手指教!!!