异步调用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};时,均可正常运行。

请各位高手指教!!!

...全文
31 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jelon 2003-08-06
  • 打赏
  • 举报
回复
to saucer:
真不好意思,犯了如此低级的错误。
感谢你的帮助,现在程序已正常运行。高手就是高手!!!
Jelon 2003-08-06
  • 打赏
  • 举报
回复
感谢saucer,我晚上再试试!
saucer 2003-08-06
  • 打赏
  • 举报
回复
oh, boy, try to change it to [MTAThread], :-)
Jelon 2003-08-06
  • 打赏
  • 举报
回复
to saucer:
我注释[STAThread]后,仍出现相同的错误。请再帮我想想解决办法,谢谢!
saucer 2003-08-06
  • 打赏
  • 举报
回复
find the following attribute in your code and remove it
[STAThread]
孟子E章 2003-08-05
  • 打赏
  • 举报
回复
http://www.google.com/search?hl=zh-CN&ie=UTF-8&oe=UTF-8&q=%E5%BC%82%E6%AD%A5%E8%B0%83%E7%94%A8+Web%E6%9C%8D%E5%8A%A1&btnG=Google%E6%90%9C%E7%B4%A2&lr=
孟子E章 2003-08-05
  • 打赏
  • 举报
回复
服务器端异步 Web 方法

http://www.microsoft.com/china/msdn/library/dnservice/html/service10012002.asp

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧