var r = WebRequest.Create(uri);
ManualResetEvent re = new ManualResetEvent(false);
r.BeginGetRequestStream(x =>
{
re.Set();
rs = r.EndGetRequestStream(a_r);
}, null);
re.WaitOne();
run OK.But this:
var r = WebRequest.Create(uri);
ManualResetEvent re = new ManualResetEvent(false);
r.BeginGetRequestStream(x =>
{
rs = r.EndGetRequestStream(a_r);
re.Set();//change
}, null);
re.WaitOne();
just hangs forever.
According to docs x=>{} lambda executed in "worker thread",but in "EndGetRequestStream" we see "AsyncHelper.BeginOnUI->UiSynchronizationContext.Current.Send()" for lambda,so we have deadlock. How understand(and resolve) that statement?
Hello, your callback method is invoked on a background thread. But inside the EndGetRequestStream method, something needs to be done on the UI thread. Thus if you call EndGetRequestStream before re.Set, since the UI thread is hung, EndGetRequestStream cannot
continue. If you call EndGetRequestStream after re.Set, the UI thread can continue.
shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
I don't understand, so it's Async OR NOT? since it's requiring the UI thread to keep on going then how is this ASYNC? can someone explain why this implementation is called async?
XASD
Member
97 Points
60 Posts
BeginGetRequestStream anomaly
Jun 16, 2008 06:45 PM | LINK
var r = WebRequest.Create(uri); ManualResetEvent re = new ManualResetEvent(false); r.BeginGetRequestStream(x => { re.Set(); rs = r.EndGetRequestStream(a_r); }, null); re.WaitOne();run OK.But this:var r = WebRequest.Create(uri); ManualResetEvent re = new ManualResetEvent(false); r.BeginGetRequestStream(x => { rs = r.EndGetRequestStream(a_r); re.Set();//change }, null); re.WaitOne();just hangs forever.According to docs x=>{} lambda executed in "worker thread",but in "EndGetRequestStream" we see "AsyncHelper.BeginOnUI->UiSynchronizationContext.Current.Send()" for lambda,so we have deadlock. How understand(and resolve) that statement?
Thanks.
Yi-Lun Luo -...
All-Star
25149 Points
2759 Posts
Microsoft
Re: BeginGetRequestStream anomaly
Jun 18, 2008 07:55 AM | LINK
brainbox
Member
115 Points
166 Posts
Re: BeginGetRequestStream anomaly
Dec 13, 2009 06:13 PM | LINK
Zakharov Alexey, Microsoft Certified Professional Developer.
Website: witcraft.ru
Blog: weblogs.asp.net/AlexeyZakharov/
xmas__
Member
8 Points
12 Posts
Re: BeginGetRequestStream anomaly
Apr 13, 2011 03:38 PM | LINK
I don't understand, so it's Async OR NOT? since it's requiring the UI thread to keep on going then how is this ASYNC? can someone explain why this implementation is called async?