public void Should_dequeue_all_when_disposing() { var worker = new TestProcessor(); var target = new WorkerThread<int>("test", TimeSpan.FromDays(1), worker.Process); target.Enqueue(1); target.Enqueue(2); target.Enqueue(3); target.Dispose(); worker.Logs.Should().Have.SameSequenceAs(new[] { "1, 2, 3" }); }
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)); } }; }
public void Should_be_able_to_dispose_failing_worker() { var worker = new TestProcessor(); var target = new WorkerThread<int>("test", TimeSpan.FromDays(1), worker.Process); target.Enqueue(1); target.Dispose(); worker.Logs.Should().Have.SameSequenceAs(new[] { "1" }); }
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. }
public void Should_dequeue_in_batch() { var worker = new TestProcessor(); var target = new WorkerThread<int>("test", TimeSpan.FromSeconds(.75), worker.Process); target.Enqueue(1); target.Enqueue(2); target.Enqueue(3); worker.Go.WaitOne(); target.Enqueue(4); target.Enqueue(5); target.Enqueue(6); worker.Go.WaitOne(); worker.Logs.Should().Have.SameSequenceAs(new[] { "1, 2, 3", "4, 5, 6" }); }