问题描述
以下代码:
(调用返回Task的异步方法)
...
Task<int> taskInt = Globals.ThisAddIn._DAL.InsertTestAceQL();
int resInt = taskInt.Result;
MessageBox.Show("resInt= " + resInt.ToString());
...
public async Task<int> InsertTestAceQL()
{
int res = int.MinValue;
try
{
string sql = "INSERT INTO dbo.AceQLTst2 VALUES ('From Visio')";
AceQLCommand command = new AceQLCommand(sql,AceQLConn().Result);
try
{
res = await command.ExecuteNonQueryAsync();
}
catch (AceQLException ex)
{
Globals.ThisAddIn.HandleException(ex.Message);
}
}
catch (Exception ex)
{
Globals.ThisAddIn.HandleException(ex.Message);
}
return res;
}
...
导致以下错误消息:
代码被卡住了。
有人知道吗?
解决方法
没有C#代码导致任何服务器繁忙。
正在发生的事情是该代码阻止了用户界面:
int resInt = taskInt.Result;
并且Windows告诉您应用程序正忙且没有响应-阻止了用户界面。