コード例 #1
0
        /// <summary>
        /// Экспорт закончен
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!e.Cancelled)
            {
                if (e.Error != null)
                {
                    Manager.UI.ShowMessage(e.Error.Message);
                }
                else
                {
                    try
                    {
                        var exporterResult = e.Result as XamExporterResult;
                        if (exporterResult != null && exporterResult.Workbook != null)
                        {
                            using (var exportStream = new MemoryStream())
                            {
                                exporterResult.Workbook.Save(exportStream);
                                exportStream.Position = 0;

                                FileAdapter.SaveFile(exportStream, exporterResult.FileName, "xlsx", Manager.UI.ShowMessage,
                                                     (message, fn) => Manager.UI.ShowYesNoDialog("Открыть файл \"" + Path.GetFileName(exporterResult.FileName) + "\" ?", () =>
                                {
                                    Proryv.AskueARM2.Client.Visual.Common.CommonEx.OpenSavedFile(fn);
                                    exporterResult.FileName = string.Empty;
                                }));
                            }

                            ClearProgressIndicator(exporterResult.ClickedButton);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.Message);
                    }
                }
            }

            var worker = sender as BackgroundWorker;

            if (worker != null)
            {
                try
                {
                    worker.DoWork             -= worker_DoWork;
                    worker.RunWorkerCompleted -= worker_RunWorkerCompleted;
                }
                catch
                {
                }
            }

            //fe.IsEnabled = true;

            GC.Collect(0);
            //GC.WaitForPendingFinalizers();

            //progress.Abort();
            //btnValidate.IsEnabled = progress.IsEnabled = true;
        }