I think you're confused about how asynchronous code exploitation works and how callback execution fits the calling code.
Inside GetRequestStreamCallback after calling request.BeginGetResponse method will continue to execute and will simply end in your example.
It is not known when (or even if) the ResponseCallback will execute or what will happen in the user interface thread when this happens. Because of this, ResponseCallback will be executed in another thread.
It is possible to use code in a callback in a user interface thread (with which you will need to interact with the user interface) using Dispatcher.BeginInvoke . However, you cannot do this in the context of another method.
Although I would not recommend it, you can take a look at this discussion to make the callback execute synchronously. This will block your UI thread, although not recommended.
source share