Ejemplo n.º 1
0
 public CMThreadPool(OperationStatus status)
 {
     _status = status;
     Task.Run(() =>
     {
         while (_runningThreads.Count > 0 || _state.Count > 0 || starting)
         {
             try
             {
                 for (int i = 0; i < _runningThreads.Count; i++)
                 {
                     if (_runningThreads[i] == null || _runningThreads[i].IsCompleted)
                     {
                         _runningThreads.RemoveAt(i);
                         i--;
                     }
                 }
                 if (_runningThreads.Count < ContentMigrationHandler.remoteThreads)
                 {
                     Tuple<WaitCallback, object> stateTuple = null;
                     if (_state.TryDequeue(out stateTuple))
                     {
                         _runningThreads.Add(stateTuple.Item1.BeginInvoke(stateTuple.Item2, null, null));
                     }
                     else
                     {
                         Thread.Sleep(10);
                     }
                 }
             }
             catch (Exception e)
             {
                 Log.Error("problem initializing the content migration thread", e, this);
             }
             if (_runningThreads.Count == ContentMigrationHandler.writerThreads)
                 Thread.Sleep(10);
         }
         _status.EndOperation();
     });
 }
 internal static OperationStatus RegisterEvent(RemoteContentPullArgs args)
 {
     var ret = Guid.NewGuid().ToString();
     _operation[ret] = new OperationStatus(args, ret);
     return _operation[ret];
 }
        public dynamic PullContentItem(RemoteContentPullArgs args)
        {
            OperationStatus status = RegisterEvent(args);

            return(status.OperationId);
        }