BackgroundWorker_DoWork ( object sender, DoWorkEventArgs e ) { AssertValid(); Debug.Assert(e.Argument is ProcessGraphMLFilesAsyncArgs); ProcessGraphMLFilesAsyncArgs processGraphMLFilesAsyncArgs = (ProcessGraphMLFilesAsyncArgs)e.Argument; ProcessGraphMLFilesInternal(processGraphMLFilesAsyncArgs, m_BackgroundWorker, e); }
ProcessGraphMLFilesInternal ( ProcessGraphMLFilesAsyncArgs processGraphMLFilesAsyncArgs, BackgroundWorker backgroundWorker, DoWorkEventArgs doWorkEventArgs ) { Debug.Assert(processGraphMLFilesAsyncArgs != null); Debug.Assert(backgroundWorker != null); Debug.Assert(doWorkEventArgs != null); AssertValid(); while (true) { ProcessGraphMLFilesRecursive( processGraphMLFilesAsyncArgs.GraphMLFolderPath, backgroundWorker); Int32 sleepPeriodSeconds = Properties.Settings.Default.SleepPeriodSeconds; ReportProgress(backgroundWorker, String.Format( "{0} {1} seconds." , PausingMessagePrefix, sleepPeriodSeconds )); while (sleepPeriodSeconds > 0) { if (backgroundWorker.CancellationPending) { doWorkEventArgs.Cancel = true; return; } Thread.Sleep(1000); sleepPeriodSeconds--; } } }
ProcessGraphMLFilesAsync ( String graphMLFolderPath ) { Debug.Assert(!String.IsNullOrEmpty(graphMLFolderPath)); AssertValid(); if (this.IsBusy) { throw new InvalidOperationException( "An asynchronous operation is already in progress." ); } ProcessGraphMLFilesAsyncArgs processGraphMLFilesAsyncArgs = new ProcessGraphMLFilesAsyncArgs(); processGraphMLFilesAsyncArgs.GraphMLFolderPath = graphMLFolderPath; m_BackgroundWorker = CreateBackgroundWorker(); m_BackgroundWorker.RunWorkerAsync(processGraphMLFilesAsyncArgs); }
ProcessGraphMLFilesInternal ( ProcessGraphMLFilesAsyncArgs processGraphMLFilesAsyncArgs, BackgroundWorker backgroundWorker, DoWorkEventArgs doWorkEventArgs ) { Debug.Assert(processGraphMLFilesAsyncArgs != null); Debug.Assert(backgroundWorker != null); Debug.Assert(doWorkEventArgs != null); AssertValid(); while (true) { ProcessGraphMLFilesRecursive( processGraphMLFilesAsyncArgs.GraphMLFolderPath, backgroundWorker); Int32 sleepPeriodSeconds = Properties.Settings.Default.SleepPeriodSeconds; ReportProgress(backgroundWorker, String.Format( "{0} {1} seconds." , PausingMessagePrefix, sleepPeriodSeconds ) ); while (sleepPeriodSeconds > 0) { if (backgroundWorker.CancellationPending) { doWorkEventArgs.Cancel = true; return; } Thread.Sleep(1000); sleepPeriodSeconds--; } } }
ProcessGraphMLFilesAsync ( String graphMLFolderPath ) { Debug.Assert( !String.IsNullOrEmpty(graphMLFolderPath) ); AssertValid(); if (this.IsBusy) { throw new InvalidOperationException( "An asynchronous operation is already in progress." ); } ProcessGraphMLFilesAsyncArgs processGraphMLFilesAsyncArgs = new ProcessGraphMLFilesAsyncArgs(); processGraphMLFilesAsyncArgs.GraphMLFolderPath = graphMLFolderPath; m_BackgroundWorker = CreateBackgroundWorker(); m_BackgroundWorker.RunWorkerAsync(processGraphMLFilesAsyncArgs); }