예제 #1
0
        public void OpDlgTest()
        {
            var idlg = new IOperationsProgressDialog();

            idlg.StartProgressDialog(IntPtr.Zero, OPPROGDLGF.OPPROGDLG_DEFAULT);
            idlg.SetOperation(SPACTION.SPACTION_FORMATTING);
            idlg.SetMode(PDMODE.PDM_RUN);
            idlg.UpdateProgress(0, 0, 0, 0, 0, 100);
            var srcd  = new Vanara.Windows.Shell.ShellFolder(KNOWNFOLDERID.FOLDERID_Documents);
            var destd = new Vanara.Windows.Shell.ShellFolder(KNOWNFOLDERID.FOLDERID_Desktop);

            idlg.UpdateLocations(srcd.IShellItem, destd.IShellItem);
            var rnd = new Random();

            for (uint i = 0; i < 100; i++)
            {
                if (idlg.GetOperationStatus() == PDOPSTATUS.PDOPS_CANCELLED)
                {
                    break;
                }
                idlg.UpdateProgress(i * 1024, 102400, i * 1024, 102400, i, 100);
                Thread.Sleep(rnd.Next(50, 250));
            }
            idlg.StopProgressDialog();
        }
예제 #2
0
        private void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            int hr;

            if (e.ProgressPercentage == UPDATE_STATUS)
            {
                hr = _dialog.GetOperationStatus(out _status);
                if (Debugger.IsAttached)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                return;
            }

            if (!(e.UserState is ProgressChangedData data))
            {
                return;
            }

            // ReportProgress doesn't allow values outside this range. However, CancellationPending will call
            // BackgroundWorker.ReportProgress directly with a value that is outside this range to update the value of the property.
            if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100)
            {
                hr = _dialog.UpdateProgress((ulong)data.CurrentProgress, (ulong)data.TotalProgress,
                                            (ulong)data.ProcessedSize, (ulong)data.TotalSize,
                                            (ulong)data.ProcessedItems, (ulong)data.TotalItems);
                Marshal.ThrowExceptionForHR(hr);
                OnProgressChanged(new ProgressChangedEventArgs(e.ProgressPercentage, data.UserState));
            }
            else
            {
                hr = _dialog.UpdateLocations(data.Source, data.Destination, data.Current);
                Marshal.ThrowExceptionForHR(hr);
                OnProgressChanged(new ProgressChangedEventArgs(e.ProgressPercentage, data.UserState));
            }
        }