某些C#代码导致“服务器繁忙”错误消息

问题描述

以下代码:

(调用返回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;
        }
...

导致以下错误消息:

代码被卡住了。

Server Busy

有人知道吗?

解决方法

没有C#代码导致任何服务器繁忙。

正在发生的事情是该代码阻止了用户界面:

int resInt = taskInt.Result;

并且Windows告诉您应用程序正忙且没有响应-阻止了用户界面。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...