我正在使用Windows 8 CP,並發現在我的應用程序中,我無法正確獲取新的異步/等待機制。等待/異步問題
這個方法我顯示你將作爲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!
}
什麼給?
它能做什麼,而不是工作?它的行爲如何? – 2012-03-14 15:30:57
請參閱內嵌註釋顯示執行。 – 2012-03-14 15:32:00
抱歉,我錯過了那些。 – 2012-03-14 15:33:41