Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

BeginGetRequestStream anomaly RSS

3 replies

Last post Apr 13, 2011 03:38 PM by xmas__

(0)
  • XASD

    XASD

    Member

    97 Points

    60 Posts

    BeginGetRequestStream anomaly

    Jun 16, 2008 06:45 PM | LINK

    Following code:
    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 - MSFT

    Yi-Lun Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: BeginGetRequestStream anomaly

    Jun 18, 2008 07:55 AM | LINK

    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.
  • brainbox

    brainbox

    Member

    115 Points

    166 Posts

    Re: BeginGetRequestStream anomaly

    Dec 13, 2009 06:13 PM | LINK

    Yi-Lun it very strange that EndGetRequestStream require something to be done on UI thread. Are you plan to fix it in future version?
    Cheers,
    Zakharov Alexey, Microsoft Certified Professional Developer.

    Website: witcraft.ru
    Blog: weblogs.asp.net/AlexeyZakharov/
  • xmas__

    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?