コード例 #1
0
ファイル: Ribbon1Math.cs プロジェクト: pockees/1Math
        private async void ButtonUrlCheck_ClickAsync(object sender, RibbonControlEventArgs e)
        {
            ExcelStatic.StartTask();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            StatusForm statusForm = new StatusForm();

            statusForm.FormClosing += (object s, FormClosingEventArgs eventArgs) => cancellationTokenSource.Cancel();
            AccessibilityChecker accessibilityChecker = new AccessibilityChecker()
            {
                ResultOffSet = this.OffSet
            };

            accessibilityChecker.Reportor.ProgressChange += statusForm.ChangeProgress;
            accessibilityChecker.Reportor.MessageChange  += statusForm.ChangeMessage;
            try
            {
                await accessibilityChecker.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
        }
コード例 #2
0
        private async void ButtonQRAsync_Click(object sender, RibbonControlEventArgs e)
        {
            ExcelStatic.StartTask();
            string selectedPath;

            using (System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog())
            {
                folderBrowserDialog.Description = "请选择二维码的保存位置:";
                if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    selectedPath = folderBrowserDialog.SelectedPath;
                }
                else
                {
                    return;
                }
            }
            QRGenerator qRGenerator = new QRGenerator(selectedPath)
            {
                ResultOffSet = this.OffSet
            };
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            StatusForm statusForm = new StatusForm();

            statusForm.Show();
            statusForm.FormClosing              += (object s, System.Windows.Forms.FormClosingEventArgs formClosingEventArgs) => cancellationTokenSource.Cancel();
            qRGenerator.Reportor.MessageChange  += statusForm.ChangeMessage;
            qRGenerator.Reportor.ProgressChange += statusForm.ChangeProgress;
            try
            {
                await qRGenerator.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
        }
コード例 #3
0
ファイル: Ribbon1Math.cs プロジェクト: pockees/1Math
        private async void SplitButtonMediaDuration_Click(object sender, RibbonControlEventArgs e)
        {
            //我有点搞不懂了
            //如果这个事件处理程序作为Async void方法,在Ribbon里直接运行,就会有大量内存无法释放
            //但改成普通void方法,在方法内部用action封装一个async方法运行,就不会出现内存无法释放的情况
            //Action action = async() =>
            //  {
            ExcelStatic.StartTask();
            MediaInfoChecker mediaDurationChecker = new MediaInfoChecker()
            {
                ResultOffSet  = this.OffSet,
                CheckDuration = true
            };
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            StatusForm statusForm = new StatusForm();

            statusForm.Show();
            mediaDurationChecker.Reportor.MessageChange  += statusForm.ChangeMessage;
            mediaDurationChecker.Reportor.ProgressChange += statusForm.ChangeProgress;
            statusForm.FormClosing += (object s, System.Windows.Forms.FormClosingEventArgs formClosingEventArgs) => cancellationTokenSource.Cancel();
            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            try
            {
                await mediaDurationChecker.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                mediaDurationChecker.Reportor.MessageChange  -= statusForm.ChangeMessage;
                mediaDurationChecker.Reportor.ProgressChange -= statusForm.ChangeProgress;
                mediaDurationChecker = null;
                System.GC.Collect();
                ExcelStatic.EndTask();
            }
            //  };
            //action.Invoke();
        }
コード例 #4
0
ファイル: Ribbon1Math.cs プロジェクト: pockees/1Math
        private async void ButtonAntiMerge_ClickAsync(object sender, RibbonControlEventArgs e)
        {
#if DEBUG
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            ExcelStatic.StartTask();
            MergeAreas mergeAreas = new MergeAreas();
            StatusForm statusForm = new StatusForm();
            statusForm.Show();
            statusForm.SetStyle(ProgressBarStyle.Marquee);
            mergeAreas.Found += ((object s, EventArgs ea) => statusForm.SetStyle(ProgressBarStyle.Continuous));
            mergeAreas.Reportor.MessageChange  += statusForm.ChangeMessage;
            mergeAreas.Reportor.ProgressChange += statusForm.ChangeProgress;
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            statusForm.FormClosing += delegate
            {
                cancellationTokenSource.Cancel();
            };

            try
            {
                await mergeAreas.SafelyUnMergeAndFill(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
#if DEBUG
            System.Windows.Forms.MessageBox.Show($"耗时{stopwatch.Elapsed.TotalSeconds.ToString()}秒");
#endif
        }