【发布时间】:2012-10-24 07:19:22
【问题描述】:
可能重复:
Why does ManualResetEvent fail to work in this synchronous call using Silverlight 4?
我在 MainPage.Xaml.cs 中有以下代码
ManualResetEvent wait = new ManualResetEvent(false);
Service1Client wcf = new Service1Client();
wcf.DoWorkCompleted += (o, ev) =>
{
int s = (int)ev.Result;
wait.Set();
};
wcf.DoWorkAsync();
wait.WaitOne();
//My other part of code where I'd like the value of `int s`.
....
Service1.svc.cs 代码如下。
public class Service1 : IService1
{
public int DoWork()
{
return 5;
}
}
直到DoWork 完成,我希望我的代码等待,所以我编写了这段代码。虽然在 WaitOne 指令 (Service1.svc.cs) 之后方法 DoWork() 根本不会被调用。应用程序将留在那里只是不做任何事情。我以前在 SilverLight 4 的另一台机器上做过这个,它按预期工作。现在我正在使用 SilverLight 3。
【问题讨论】:
标签: c# multithreading wcf silverlight