I'm working on Windows 8 CP and discovered that in my app, I'm unable to properly get the new async/await mechanism to work.
This method I am showing you will work when run as a UnitTest (called from a unit test) but when ran normally, it DOES NOT WORK!
StreamSocket _client;
private void Start() {
SomeMethod();
SomeOtherMethod();
}
private async void SomeMethod(string sample)
{
var request = new GetSampleRequestObject(sample);
byte[] payload = ConvertToByteArray(request, Encoding.UTF8);
DataWriter writer = new DataWriter(_client.OutputStream);
writer.WriteBytes(payload);
await writer.StoreAsync(); // <--- after this executes, it exits the method and continues
await writer.FlushAsync(); // <--- breakpoint never reaches here, instead
writer.DetachStream();
}
private void SomeOtherMethod()
{
string hello = "hello"; // <--- it skips everything and reaches here!
}
What gives?
I think you have to put await in front of your initial SomeMethod call in the Start function:
await SomeMethod();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With