コード例 #1
0
        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();
            }
        }
コード例 #2
0
 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();
 }
コード例 #3
0
 /// <summary>
 /// Abort this thread - can only be called *before* Run() has been called.
 /// </summary>
 public void Abort()
 {
     _worker.Abort();
 }
コード例 #4
0
 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();
 }