當前位置: 首頁>>代碼示例>>C#>>正文


C# BackgroundWorker.RunBackground方法代碼示例

本文整理匯總了C#中System.ComponentModel.BackgroundWorker.RunBackground方法的典型用法代碼示例。如果您正苦於以下問題:C# BackgroundWorker.RunBackground方法的具體用法?C# BackgroundWorker.RunBackground怎麽用?C# BackgroundWorker.RunBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.BackgroundWorker的用法示例。


在下文中一共展示了BackgroundWorker.RunBackground方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MinimizeToFile

        public void MinimizeToFile(string targetFile)
        {
            var targetSkydFile = ChromatogramCache.FinalPathForName(targetFile, null);
            using (var skydSaver = new FileSaver(targetSkydFile))
            using (var scansSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCANS_EXT, true))
            using (var peaksSaver = new FileSaver(targetSkydFile + ChromatogramCache.PEAKS_EXT, true))
            using (var scoreSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCORES_EXT, true))
            {
                skydSaver.Stream = File.OpenWrite(skydSaver.SafeName);
                using (var longWaitDlg = new LongWaitDlg(DocumentUIContainer))
                {
                    longWaitDlg.PerformWork(this, 1000,
                                            longWaitBroker =>
                                                {
                                                    longWaitBroker.Message = Resources.MinimizeResultsDlg_MinimizeToFile_Saving_new_cache_file;
                                                    try
                                                    {
                                                        using (var backgroundWorker =
                                                            new BackgroundWorker(this, longWaitBroker))
                                                        {
                                                            backgroundWorker.RunBackground(skydSaver.Stream,
                                                                scansSaver.FileStream, peaksSaver.FileStream, scoreSaver.FileStream);
                                                        }
                                                    }
                                                    catch (ObjectDisposedException)
                                                    {
                                                        if (!longWaitBroker.IsCanceled)
                                                        {
                                                            throw;
                                                        }
                                                    }
                                                });

                    if (longWaitDlg.IsCanceled)
                    {
                        return;
                    }
                }

                var skylineWindow = (SkylineWindow) DocumentUIContainer;
                if (!skylineWindow.SaveDocument(targetFile, false))
                {
                    return;
                }
                try
                {
                    var measuredResults = DocumentUIContainer.Document.Settings.MeasuredResults.CommitCacheFile(skydSaver);
                    SrmDocument docOrig, docNew;
                    do
                    {
                        docOrig = DocumentUIContainer.Document;
                        docNew = docOrig.ChangeMeasuredResults(measuredResults);
                    } while (!DocumentUIContainer.SetDocument(docNew, docOrig));
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(
                        string.Format(Resources.MinimizeResultsDlg_MinimizeToFile_An_unexpected_error_occurred_while_saving_the_data_cache_file__0__,
                                                targetFile),
                        x.Message);
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
                skylineWindow.InvalidateChromatogramGraphs();
            }
            DialogResult = DialogResult.OK;
        }
開發者ID:lgatto,項目名稱:proteowizard,代碼行數:67,代碼來源:MinimizeResultsDlg.cs


注:本文中的System.ComponentModel.BackgroundWorker.RunBackground方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。