6

Possible Duplicate:
Why does ManualResetEvent fail to work in this synchronous call using Silverlight 4?

I have a below code in 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 has the code below .

public class Service1 : IService1
{
  public int DoWork()
  {
    return 5;
  }
}

Till the DoWork is completed I want my code to wait so I have written this code. Though after WaitOne instruction (Service1.svc.cs) method DoWork() won't be called at all. Application will stay there only doesn't do anything. I have worked on this before in another machine in SilverLight 4 and it was working as expected. Now I'm using SilverLight 3.

0

1 Answer 1

0

You're probably causing a deadlock on the UI thread by calling wait.WaitOne().

When the async operation is completed, it tries to invoke the DoWorkCompleted through the UI dispatcher. Although it will successfully queue the invocation, it will never dequeue since the UI thread is blocked on WaitOne().

In my opinion, you should avoid this workaround and just do async calls.

1
  • Eren I created whole new application and tried the same still not working.I am using navigation application. Oct 24, 2012 at 9:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.