我正在使用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