title: Deadlock - Windows Phone 8 BeginGetResponse c#
body: <p>I have two processes running on my UI thread. However, when I run the first, with BeginGetStream functionality, it enters the cycle and waits for its execution and returns the result when you are ready, but in the second run, through the BeginGetResponse functionality, this "die" there and the program does not continue and does not return me the value I want. Within these processes use the IasynResult.</p>
  
  <p>I've tried:</p>
  
  <ul>
  <li><p>Convert to a Task (Task.Run)</p></li>
  <li><p>Allocate the process a new thread (Thread x = new Thread ())</p></li>
  <li><p>Set the parameter ConfigureAwait (ConfigureAwait (      continueOnCapturedContext: false), ConfigureAwait (false));</p></li>
  <li><p>Convert to asyncronos methods and apply the "await"</p></li>
  <li><p>Use the AutoResetEvent to wait for the process to complete and do not proceed.</p></li>
  <li><p>Placement thread to sleep (Thread.Sleep)</p></li>
  <li><p>Use of Thread.Start, Thread.Join</p></li>
  <li><p>etc....</p></li>
  </ul>
  
  <p>I have essentially three functions(Function1,Function2 and Function3).
  Initially,I only use the Function2 and function3 and everything ok.
  Then, in anext order,where I do not want the UI thread lock,it blocks,and this time chamos the three functions I have, but the application blocks me when I make the request for BeginGetResponse in Function2.Not out there.
  (Putting the whole project in asynchronous is very costly,so this option will be the last.)
  I do not knowwhat elsecan I do...:(
  Some code example:</p>
  
  <hr>
  
  <p>Function 1:</p>
  
  <pre><code>public void Function1()
               {
  
                    {           
  HttpWebRequest requestHttp = (HttpWebRequest)HttpWebRequest.CreateHttp(new Uri(serverUrl, UriKind.Absolute));
  
                          string RString = string.Format("rftoken=123456789");
                          AutoResetEvent handler = new AutoResetEvent(false);
                          IAsyncResult TestResult= null;
                          try
                          {
                              requestHttp.BeginGetRequestStream(
                                  (IAsyncResult result) =&gt;
                                  {
                                      TestResult= result;
                                      handler.Set();
                                  }, requestHttp );
  
                              handler.WaitOne();
  
                          }
                          catch (Exception) { }
  
                          return Function2(TestResult, RString );
                      }               
                  }
  </code></pre>
  
  <p>--------FUNCTION 2 ----------------------------------------------------------------------------------------</p>
  
  <pre><code>private Example Function2(IAsyncResult TestResult2, string RString2)
  
      try
      {
          HttpWebRequest request = (HttpWebRequest)TestResult2.AsyncState;
          Stream strm = request.EndGetRequestStream(TestResult2);
          StreamWriter writer = new StreamWriter(strm);
          writer.Write(RString2);
          writer.Dispose();
      }
      catch
      {}
  
      AutoResetEvent handler = new AutoResetEvent(false);
      IAsyncResult Async= null;
  
      try
      {
          requestHttp.BeginGetRequestStream(
              (IAsyncResult result) =&gt;
              {
                  Async= result;
                  handler.Set();
              }, requestHttp );
  
          handler.WaitOne();
  
      }
      catch (Exception) { }
  
      return Function3(Async);
  } 
  }
  </code></pre>
  
  <p>------------FUNCTION 3 ---------------------------------------------------------------------------------------</p>
  
  <pre><code>   private Example Function3 (IAsyncResult Async3)
  
  {....}
  </code></pre>
  
  <hr>
  
  <p>... I do not know what else to try ... Someone can help me.</p>
  
  <p>Thank you.</p>