我知道我无法在 Windows Phone 7 中进行真正的同步调用。但是,我试图至少阻止线程处理,直到进行异步调用或超时。我尝试了以下方法,但似乎我的应用程序只是忽略了它,放弃了呼叫,并且没有返回。任何想法为什么?
我正在尝试在绑定期间使用值转换器更新值。
public ManualResetEvent _event;
public void GetSync()
{
_event = new ManualResetEvent(false);
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(ReadCompleted);
wc.OpenReadAsync(new Uri("My URL"));
// block until async call is complete
_event.WaitOne(5000);
}
private void ReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var serializer = new XmlSerializer(typeof(MyFormatter));
// The property below is accessed back in the Value Converter for binding
StronglyTypedObject = (StObject)serializer.Deserialize(e.Result);
_event.Set();
}