Exemplo n.º 1
0
        /// <summary>结束异步执行</summary>
        private static void EndExecuteAsync(IAsyncResult ar)
        {
            var result      = (AsyncResult)ar;
            var beginAction = result.AsyncDelegate.As <Action>();
            var state       = ar.AsyncState.As <List <object> >();

            try
            {
                beginAction.EndInvoke(ar);
                state.Add(null);
            }
            catch (Exception ex)
            {
                ModuleBootstrapper.Error(beginAction.Target, beginAction.Method.Name, ex);
                state.Add(ex);
            }
            var form = state[0].As <Form>();

            if (form.InvokeRequired)
            {
                Action <object> endActionSync = EndExecuteSync;
                form.BeginInvoke(endActionSync, state);
                return;
            }
            EndExecuteSync(state);
        }
Exemplo n.º 2
0
        /// <summary>结束异步执行</summary>
        private static void EndExecuteSync(object asyncState)
        {
            var state     = asyncState.As <List <object> >();
            var index     = 0;
            var form      = state[index++].As <Form>();
            var workItem  = state[index++].As <WorkItem>();
            var splash    = state[index++].As <ISplashService>();
            var endAction = state[index++].As <Action <bool> >();
            var controls  = state[index++].As <List <Control> >();
            var exAction  = state[index++].As <Exception>();

            splash.Hide();
            try
            {
                endAction(exAction == null);
                if (exAction != null)
                {
                    workItem.Alert(exAction.GetFullMessage());
                }
            }
            catch (Exception ex)
            {
                ModuleBootstrapper.Error(endAction.Target, endAction.Method.Name, ex);
                workItem.Alert(ex.GetFullMessage());
                if (exAction != null)
                {
                    workItem.Alert(exAction.GetFullMessage());
                }
            }
            finally
            {
                splash.Hide();
                EnableControls(controls);
            }
        }