c#异步执行一段代码

            Thread th = new Thread(
                                    delegate()
                                    {
                                        try
                                        {
                                            HttpHelper helper = new HttpHelper();
                                            HttpItem item = new HttpItem()
                                            {
                                                URL = APIUrl + "api/devicemanager/synchroDeviceInfoByUsername?username=" + username,//URL     必需项
                                                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                                                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
                                                Referer = Request.Url.AbsoluteUri//来源URL     可选项

                                            };
                                            HttpResult result = helper.GetHtml(item);
                                            DeviceAPIResult<object> apiresult = JsonConvert.DeserializeObject<DeviceAPIResult<object>>(result.Html);
                                            if (apiresult != null && !string.IsNullOrEmpty(apiresult.success) && apiresult.success.ToLower() == "true")
                                            {
                                                Log4WebHelper.WriteLog(string.Format("将用户{0}使exchange设备信息同步到DB成功", username), LogErrorLevel.INFO);
                                            }
                                            else
                                            {
                                                Log4WebHelper.WriteLog(string.Format("将用户{0}使exchange设备信息同步到DB失败", username), LogErrorLevel.INFO);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            Log4WebHelper.WriteLog(string.Format("将用户{0}使exchange设备信息同步到DB失败,失败信息:{1}", username, ex.ToString()), LogErrorLevel.ERROR);
                                        }

                                    }
           );
            th.IsBackground = true;
            th.Start();


版权声明:本文为zghnpdswyp原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。