Beispiel #1
0
        //static PleaseWaitWindow _pleaseWaitDlg;

        /// <summary>
        /// Runs the specified long operation (in delegate) in separate thread and display please wait modal window.
        /// </summary>
        /// <param name="method">The method to run in background.</param>
        /// <param name="canBeCanceled">if set to <c>true</c> operation can be canceled (PleaseWait window display Cancel button).</param>
        public static bool Run(MyRunMethod method, bool canBeCanceled = false, IProgressWindow progressWindow = null, int?progressMax = null, bool useDefaultExceptionHandling = true)
        {
            bool res = true;

            if (useDefaultExceptionHandling)
            {
                UIHelper.RunWithExceptionHandling(delegate
                {
                    res = pleaseWaitImplementation(canBeCanceled, progressMax, method, progressWindow);
                });
            }
            else
            {
                res = pleaseWaitImplementation(canBeCanceled, progressMax, method, progressWindow);
            }
            return(res);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PleaseWaitContext"/> class.
 /// </summary>
 /// <param name="method">The method to run in background.</param>
 /// <param name="dlg">PleaseWaitWindow used in this context</param>
 public PleaseWaitContext(MyRunMethod method, IProgressWindow dlg)
     : base(dlg)
 {
     this.method = method;
 }
Beispiel #3
0
        //static DispatcherTimer timer = new DispatcherTimer();
        private static bool pleaseWaitImplementation(bool canBeCanceled, int?progressMax, MyRunMethod method, IProgressWindow _pleaseWaitDlg)
        {
            bool res = true;

            Debug.WriteLine("PleaseWait.Run start");
            //Cancel = false;
            // Start my lengthy Process
            // Display the Please Wait Dialog here
            if (_pleaseWaitDlg == null)
            {
                //_pleaseWaitDlg = new PleaseWaitWindow(canBeCanceled, progressMax);
                _pleaseWaitDlg = MainWindow.Instance;
            }

            Thread lengthyProcessThread = new Thread(threadRunner);

            lengthyProcessThread.SetApartmentState(ApartmentState.STA);
            lengthyProcessThread.IsBackground = true; // so not to have stray running threads if the main form is closed
            PleaseWaitContext pleaseWaitContext = new PleaseWaitContext(method, _pleaseWaitDlg);

            lengthyProcessThread.Start(pleaseWaitContext);

            IProgressWindow  temporaryWindow = _pleaseWaitDlg;
            MethodParameters par             = new MethodParameters(temporaryWindow);

            //timer.Interval = TimeSpan.FromSeconds(.5);
            //timer.Tick += delegate
            //{
            //    timer.Stop();
            //    if (/*!pendingClosing &&*/ !par.Finished)
            //    {
            //        temporaryWindow.ShowProgress();
            //    }
            //};
            temporaryWindow.Parameters = par;
            //timer.Start();
            temporaryWindow.ShowProgress(canBeCanceled, progressMax);


            Debug.WriteLine("Creating thread: " + lengthyProcessThread.ManagedThreadId);
            //if please wait thread throws exception then rethrow it
            if (pleaseWaitContext.ReturnException != null)
            {
                res = false;
                ExceptionHandler.Default.Process(pleaseWaitContext.ReturnException);
                //throw new RethrowedException(pleaseWaitContext.ReturnException);)
                throw pleaseWaitContext.ReturnException;
            }
            return(res);
        }
Beispiel #4
0
        private static bool pleaseWaitImplementation(bool canBeCanceled, int?progressMax, MyRunMethod method)
        {
            bool res = true;

            Debug.WriteLine("PleaseWait.Run start");
            //Cancel = false;
            // Start my lengthy Process
            // Display the Please Wait Dialog here
            PleaseWaitWindow _pleaseWaitDlg       = new PleaseWaitWindow(canBeCanceled, progressMax);
            Thread           lengthyProcessThread = new Thread(threadRunner);

            lengthyProcessThread.IsBackground = true; // so not to have stray running threads if the main form is closed
            PleaseWaitContext pleaseWaitContext = new PleaseWaitContext(method, _pleaseWaitDlg);

            lengthyProcessThread.Start(pleaseWaitContext);
            Debug.WriteLine("Creating thread: " + lengthyProcessThread.ManagedThreadId);
            _pleaseWaitDlg.ShowDialog();
            //if please wait thread throws exception then rethrow it
            if (pleaseWaitContext.ReturnException != null)
            {
                res = false;
                ExceptionHandler.Default.Process(pleaseWaitContext.ReturnException);
                //throw new RethrowedException(pleaseWaitContext.ReturnException);)
                throw pleaseWaitContext.ReturnException;
            }
            return(res);
        }