public static bool AsyncImportDirectory(string directory, AsyncImportDelegate completedDelegate) { BackgroundWorker importerThread = new BackgroundWorker(); Debug.Assert(m_AsyncCompletedDelegate == null); if (completedDelegate != null) { m_AsyncCompletedDelegate = completedDelegate; m_ImportDirectory = directory; importerThread.DoWork += new DoWorkEventHandler(importerThread_DoWork); importerThread.WorkerReportsProgress = true; importerThread.ProgressChanged += new ProgressChangedEventHandler(importerThread_ProgressChanged); importerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(importerThread_RunWorkerCompleted); importerThread.WorkerSupportsCancellation = true; importerThread.RunWorkerAsync(); return true; } return false; }
private static void importerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { m_AsyncCompletedDelegate.OnAsyncImportCompleted(true); m_AsyncCompletedDelegate = null; }