我正在使用 Windows 8 CP 并发现在我的应用程序中,我无法正确地使新的 async/await 机制正常工作。
我向您展示的这种方法在作为 UnitTest(从单元测试调用)运行时会起作用,但是当正常运行时,它不起作用!
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!
}
是什么赋予了?