ComponentFactory.Krypton.Toolkit.ModalWaitDialog.UpdateDialog C# (CSharp) Method

UpdateDialog() public method

Called periodically to update the wait dialog.
public UpdateDialog ( ) : void
return void
        public void UpdateDialog()
        {
            // Remember the first time the update is called
            if (!_startTimestamped)
            {
                _startTimestamped = true;
                _startTimestamp = DateTime.Now;
            }
            else
            {
                // If the dialog has not been shown yet
                if (!Visible)
                {
                    // Has initial delay expired?
                    if (DateTime.Now.Subtract(_startTimestamp).TotalMilliseconds > DELAY_SHOWING)
                    {
                        // Make this dialog visible to the user
                        Show();

                        // Start the spin timing
                        _spinTimestamp = DateTime.Now;
                    }
                }
                else
                {
                    // Has the spin delay expired?
                    if (DateTime.Now.Subtract(_spinTimestamp).TotalMilliseconds > DELAY_SPIN)
                    {
                        // Increase the spin angle by one notch
                        _spinAngle = (_spinAngle + SPIN_ANGLE) % 360;

                        // Request the spin image be redrawn
                        Invalidate();

                        // Start the next spin timing
                        _spinTimestamp = DateTime.Now;
                    }
                }
            }

            // Let any repainting or processing events be dispatched
            Application.DoEvents();
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Perform operation in a worker thread with wait dialog in main thread.
        /// </summary>
        /// <param name="op">Delegate of operation to be performed.</param>
        /// <param name="parameter">Parameter to be passed into the operation.</param>
        /// <returns>Result of performing the operation.</returns>
        public static object PerformOperation(Operation op, object parameter)
        {
            // Create a modal window for showing feedback
            using (ModalWaitDialog wait = new ModalWaitDialog())
            {
                // Create the object that runs the operation in a separate thread
                OperationThread opThread = new OperationThread(op, parameter);

                // Create the actual thread and provide thread entry point
                Thread thread = new Thread(new ThreadStart(opThread.Run));

                // Kick off the thread action
                thread.Start();

                // Keep looping until the thread is finished
                while (opThread.State == 0)
                {
                    // Sleep to allow thread to perform more work
                    Thread.Sleep(25);

                    // Give the feedback dialog a chance to update
                    wait.UpdateDialog();
                }

                // Process operation result
                switch (opThread.State)
                {
                    case 1:
                        return opThread.Result;
                    case 2:
                        throw opThread.Exception;
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        return null;
                }
            }
        }