示例#1
0
        public void AsyncCall(Control container, string statusText, int timeout, OneParameterHandler funcNeedAsync, object objPar, OneParameterHandler completedCallback)
        {
            m_Container         = container;
            m_FuncNeedAsync     = funcNeedAsync;
            m_CompletedCallBack = completedCallback;
            m_Timeout           = timeout < 0 ? -1 : timeout;

            //Edit By Xkp
            //异步调用函数的线程放到SplashForm中进行启动,避免在SplashForm起来之前函数已经返回
            //现在新线程只会处理异步函数的调用和返回,不再处理和取消相关的逻辑
            var thread = new Thread(AsyncProcessFuncThread);

            m_PSplash = CreateSplashForm(m_CanCancel, statusText, thread, objPar);
            DialogResult result = m_PSplash.ShowDialog(container);

            m_PSplash.Close();
            //如果返回结果是OK,则是从新线程返回的,如果是其他,则是从SplashForm返回
            if (result != DialogResult.OK)
            {
                m_ThreadNoNeedRun = true;

                var asyncCallResult = new AsyncCallResult();
                asyncCallResult.CallException = new AsynCallUserAbortException();
                m_CallResult = asyncCallResult;

                InvokeCompletedCallback();
            }
            else
            {
                InvokeCompletedCallback();
            }
        }
示例#2
0
        private ProgressSplash CreateSplashForm(bool cancelable, string statusText, Thread invokeThread, object threadPara)
        {
            var splashForm = new ProgressSplash(statusText, cancelable, invokeThread, threadPara);

            splashForm.StartPosition = this.m_SplashFormStartPosition;
            if (m_SplashFormStartPosition == FormStartPosition.Manual)
            {
                splashForm.SetLocation(Cursor.Position);
            }

            if (m_SplashFormBackColor != Color.Empty)
            {
                splashForm.BackColor = m_SplashFormBackColor;
            }
            return(splashForm);
        }