public static void TestInvalidOperationException() { using (WorkerGroup workerGroup = new WorkerGroup()) { IThreadWorker worker = workerGroup.CreateWorker(nameof(TestInvalidOperationException)); bool?f = null; Assert.Throws <InvalidOperationException>(() => { f = worker.HasCompleted; }); Assert.That(!f.HasValue, "No value should be set, since an exception should have occurred."); Assert.Throws <InvalidOperationException>(() => { worker.Join(); }); worker.Abort(); } }
private void DoFile(string fullName, IThreadWorker worker, Func <string, bool> preparation, Func <bool> operation) { if (!preparation(fullName)) { worker.Abort(); OnCompleted(_eventArgs); return; } worker.Work += (object workerSender, ThreadWorkerEventArgs threadWorkerEventArgs) => { operation(); }; worker.Completing += (object workerSender, ThreadWorkerEventArgs threadWorkerEventArgs) => { _eventArgs.Status = threadWorkerEventArgs.Result; OnCompleted(_eventArgs); }; worker.Run(); }
/// <summary> /// Abort this thread - can only be called *before* Run() has been called. /// </summary> public void Abort() { _worker.Abort(); }
private void DoFile(string fullName, IThreadWorker worker, Func<string, bool> preparation, Func<bool> operation) { if (!preparation(fullName)) { worker.Abort(); OnCompleted(_eventArgs); return; } worker.Work += (object workerSender, ThreadWorkerEventArgs threadWorkerEventArgs) => { operation(); }; worker.Completing += (object workerSender, ThreadWorkerEventArgs threadWorkerEventArgs) => { _eventArgs.Status = threadWorkerEventArgs.Result; OnCompleted(_eventArgs); }; worker.Run(); }