예제 #1
0
 public void DoBeginAccept(AcceptAsyncResult asyncResult)
 {
     if (!Active)
         throw new InvalidOperationException("mustlisten");
     var processed = false;
     var watcher = this;
     var success = FileWatcherError.Success;
     var acceptQueue = GetAcceptQueue();
     var lockTaken = false;
     try
     {
         Monitor.Enter(watcher, ref lockTaken);
         if (acceptQueue.Count == 0)
         {
             object result = null;
             try { success = DoWaitResult(out result); }
             catch (ObjectDisposedException) { success = FileWatcherError.OperationAborted; }
             switch (success)
             {
                 case FileWatcherError.WouldBlock:
                     acceptQueue.Enqueue(asyncResult);
                     if (!SetAsyncEventSelect())
                     {
                         acceptQueue.Dequeue();
                         throw new ObjectDisposedException(base.GetType().FullName);
                     }
                     goto end;
                 case FileWatcherError.Success:
                     asyncResult.Result = result;
                     break;
                 default:
                     asyncResult.ErrorCode = (int)success;
                     break;
             }
             processed = true;
         }
         else
             acceptQueue.Enqueue(asyncResult);
     }
     finally { if (lockTaken) Monitor.Exit(watcher); }
     end:
     if (!processed)
         return;
     if (success == FileWatcherError.Success)
         asyncResult.InvokeCallback();
     else
     {
         var ex = new FileWatcherException(success);
         if (_logger != null) _logger.Debug("Exception:DoBeginAccept", ex);
         throw ex;
     }
 }
예제 #2
0
 private void WaitResultCallback(AcceptAsyncResult asyncResult)
 {
     if (!Active)
         throw new InvalidOperationException("mustlisten");
     using (var tx = new TransactionScope(TransactionScopeOption.Suppress))
         foreach (var r in _tcs.Task.Result)
             switch (r.Error)
             {
                 case FileWatcherError.Success:
                     asyncResult.Result = r;
                     asyncResult.InvokeCallback();
                     break;
                 default:
                     //asyncResult.ErrorCode = (int)r.Error;
                     throw new FileWatcherException(r.Error);
             }
     //var success = FileWatcherError.Success;
     //IEnumerable<FileWatcherFile> result;
     //lock (this)
     //{
     //result = _tcs.Task.Result;
     //success = result.Error;
     //switch (success)
     //{
     //    case FileWatcherError.Success:
     //        asyncResult.Result = result;
     //        break;
     //    default:
     //        asyncResult.ErrorCode = (int)success;
     //        break;
     //}
     //}
 }