0
我正在使用Brokered UWP組件項目模板(https://visualstudiogallery.msdn.microsoft.com/d2e9cac0-66a8-464a-a902-55ae765c8e6e),並測試我是否可以從代理組件調用異步方法。Brokered UWP組件項目模板和異步
所以我代替BrokeredComponent1類:
namespace Server
{
public sealed class BrokeredComponent1
{
public string GetValue()
{
return "Hello .NET world";
}
}
}
由:
namespace Server
{
public sealed class BrokeredComponent1
{
public IAsyncOperation<string> GetValueAsync()
{
return Task.Run(() =>
{
Thread.Sleep(3000);
return "Hello .NET world";
}).AsAsyncOperation();
}
}
}
然後叫它的MainPage在Button_Click方法是這樣的:
string brokeredComponentValue = await bc.GetValueAsync();
一切似乎都工作在調試模式(3秒後出現「Hello .NET world」),但我無法完成任務k在發佈模式下,當我點擊按鈕時,應用程序只會崩潰。
有什麼想法?