public static void Init() { if (init) return; init = true; worker = new WorkerThread(); thread = new Thread( delegate() { LoggingService.Info("start background compiler"); worker.RunLoop(); } ); thread.IsBackground = true; thread.Name = "CSBackgroundCompiler"; ParserService.ParserUpdateStepFinished += delegate { if (WorkbenchSingleton.Workbench.ActiveViewContent == null) return; if (ParserService.LoadSolutionProjectsThreadRunning) return; ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; if (provider == null) return; ParseInformation parseInfo = ParserService.GetExistingParseInformation(provider.TextEditor.FileName); if (parseInfo == null) return; string fileName = provider.TextEditor.FileName; string fileContent = provider.TextEditor.Document.Text; IProjectContent pc = parseInfo.CompilationUnit.ProjectContent; if (currentWork == null) thread.Start(); if (currentWork == null || currentWork.IsCompleted) currentWork = worker.Enqueue(() => RunCompile(fileName, fileContent, pc)); }; }
static void UpdateClipboardContainsText() { if (currentWorker != null && !currentWorker.IsCompleted) return; if (workerThread == null) { workerThread = new WorkerThread(); Thread t = new Thread(new ThreadStart(workerThread.RunLoop)); t.SetApartmentState(ApartmentState.STA); t.IsBackground = true; t.Name = "clipboard access"; t.Start(); } currentWorker = workerThread.Enqueue(DoUpdate); // wait a few ms in case the clipboard can be accessed without problems WaitForSingleObject(currentWorker.AsyncWaitHandle.SafeWaitHandle, 50); // Using WaitHandle.WaitOne() pumps some Win32 messages. // To avoid unintended reentrancy, we need to avoid pumping messages, // so we directly call the Win32 WaitForSingleObject function. // See SD2-1638 for details. }