The fact is that I came across this a little more often than never, but when I had to, I somehow did it. In general, there is one function in Silverlight.
private void button1_Click(object sender, RoutedEventArgs e) { Uri mainpage = new Uri("http://192.168.1.101:3000/"); HttpWebRequest _webrequest; _webrequest = (HttpWebRequest)HttpWebRequest.Create(mainpage); RequestState rstate = new RequestState(); rstate.request = _webrequest; try { IAsyncResult result = (IAsyncResult)_webrequest.BeginGetResponse(new AsyncCallback(RespCallback), rstate); allDone.WaitOne(); // Release the HttpWebResponse resource. rstate.response.Close(); } catch (WebException wee) { MessageBox.Show("\nException raised!\n" + "Message: " + wee.Message + "\nStatus: " + wee.Status + "\n", "Error!", MessageBoxButton.OKCancel); } catch (Exception ee) { MessageBox.Show("\nException raised!\n" + "Message: " + ee.Message + "\n", "Error!", MessageBoxButton.OKCancel); } }
allDone.WaitOne();
waiting for the asynchronous call to complete. But at this stage, the program hangs, apparently because the error in the call. To identify them, I placed breakpoints in the RespCallback function, but for some reason the program never stops at them.
Update
I realized that the asynchronous function does not start at all, that is, it starts when the main one (which starts it) is completed. That is, only after allDone.WaitOne (); and rstate.response.Close () ;. But this does not happen because allDone.WaitOne () is waiting for a flag that is set when the RespCallback call is completed