Beispiel #1
0
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // Allow the application to continue running after an exception has been thrown but not handled
            Exception ex = e.ExceptionObject;

            ex.Alert();
            e.Handled = true;
        }
Beispiel #2
0
        /// <summary>
        /// 使用异步线程执行某个Action
        /// </summary>
        /// <param name="isIndeterminate">是否需要不停的来回显示提示条。
        /// 如果是false:可以使用ActionParam.ProgressValue来设置进度条进度。</param>
        /// <param name="action">The action.</param>
        /// <param name="endAsyncCallBack">执行完异步操作后调用的回调函数</param>
        /// <param name="promptContent">Content of the prompt.</param>
        public static void Execute(bool isIndeterminate,
                                   Action <IProgressReporter> action,
                                   Action endAsyncCallBack = null,
                                   string promptContent    = null)
        {
            WaitDialog win = new WaitDialog();

            if (promptContent != null)
            {
                win.Text = promptContent;
            }
            if (isIndeterminate)
            {
                win.IsIndeterminate = true;
            }

            //在后台线程中,执行这个操作
            //ThreadHelper.SafeInvoke(() =>
            ThreadPool.QueueUserWorkItem(e =>
            {
                Exception exception = null;
                try
                {
                    //执行Action
                    action(new ActionParam(win));
                }
                catch (Exception ex)
                {
                    //保存下来,在关闭窗口后再弹出。
                    exception = ex;
                }
                finally
                {
                    //执行完毕,关闭提示框
                    Action closeWindow = () =>
                    {
                        win.Close();
                        if (exception != null)
                        {
                            exception.Alert();
                        }

                        if (endAsyncCallBack != null)
                        {
                            endAsyncCallBack();
                        }
                    };
                    win.Dispatcher.BeginInvoke(closeWindow);
                }
            });

            //打开提示框
            win.Show();
        }