asd613613
asd613613
2017-02-09 04:45

C#中 没有循环的异步操作如何中止

1

private async Task CheckServer()
{

        SqlConnection mySqlConnection = new SqlConnection();
        mySqlConnection.ConnectionString = UserInfo.Session.ConnectString1;
        try
        {
            await Task.Run(() => mySqlConnection.Open());
            mySqlConnection.Close();
            UserInfo.Session.PublicIP = await UtilConv.GetPublicIP();
        }
        catch (Exception)
        {
            return "远程服务器连接失败,请检查远程服务器设置";
        }
        return "1";
    }
            public async void CheckDB()
    {
                    var result= await CheckServer();
            }

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答