C# 方便使用异步调用

Tags: C#

使用 async  await 

>= .net 4.5

        private async void ReExecNode(object obj)
        {
            try
            {
                ServiceProvider.GetEvent<BusyEvent>().Publish(true);
var paramDict = new Dictionary<string, object>(); Func<Task<object>> taskFunc = () => { return System.Threading.Tasks.Task.Run(() => { return Service.Call(paramDict); }); }; var result = await taskFunc(); if (result != null && (bool)result) {
//Do something
} } catch (Exception ex) { MessageBox.Show("执行失败!\r\n" + ex.Message); } finally { ServiceProvider.GetEvent<BusyEvent>().Publish(false); } }

1 Comment

Add a Comment