Beispiel #1
0
        private void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _dialog.StopProgressDialog();
            Marshal.ReleaseComObject(_dialog);
            _dialog = null;
            if( _currentAnimationModuleHandle != null )
            {
                _currentAnimationModuleHandle.Dispose();
                _currentAnimationModuleHandle = null;
            }

            OnRunWorkerCompleted(new RunWorkerCompletedEventArgs((!e.Cancelled && e.Error == null) ? e.Result : null, e.Error, e.Cancelled));
        }
Beispiel #2
0
        private void RunProgressDialog(IntPtr owner, object argument)
        {
            if( _backgroundWorker.IsBusy )
                throw new InvalidOperationException(Properties.Resources.ProgressDialogRunning);

            if( Animation != null )
            {
                try
                {
                    _currentAnimationModuleHandle = Animation.LoadLibrary();
                }
                catch( Win32Exception ex )
                {
                    throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
                catch( System.IO.FileNotFoundException ex )
                {
                    throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
            }

            _cancellationPending = false;
            _dialog = new Interop.ProgressDialog();
            _dialog.SetTitle(WindowTitle);
            if( Animation != null )
                _dialog.SetAnimation(_currentAnimationModuleHandle, (ushort)Animation.ResourceId);

            if( CancellationText.Length > 0 )
                _dialog.SetCancelMsg(CancellationText, null);
            _dialog.SetLine(1, Text, UseCompactPathsForText, IntPtr.Zero);
            _dialog.SetLine(2, Description, UseCompactPathsForDescription, IntPtr.Zero);

            Interop.ProgressDialogFlags flags = Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.Normal;
            if( owner != IntPtr.Zero )
                flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.Modal;
            switch( ProgressBarStyle )
            {
            case ProgressBarStyle.None:
                flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.NoProgressBar;
                break;
            case ProgressBarStyle.MarqueeProgressBar:
                if( NativeMethods.IsWindowsVistaOrLater )
                    flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.MarqueeProgress;
                else
                    flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.NoProgressBar; // Older than Vista doesn't support marquee.
                break;
            }
            if( ShowTimeRemaining )
                flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.AutoTime;
            if( !ShowCancelButton )
                flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.NoCancel;
            if( !MinimizeBox )
                flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.NoMinimize;

            _dialog.StartProgressDialog(owner, null, flags, IntPtr.Zero);
            _backgroundWorker.RunWorkerAsync(argument);
        }