Replaces AutoResetEvent with manual reset event
[pithos-ms-client] / trunk / Pithos.Core / Agents / NetworkAgent.cs
index 55a640f..293b207 100644 (file)
@@ -65,7 +65,7 @@ namespace Pithos.Core.Agents
         readonly ConcurrentDictionary<string,DateTime> _deletedFiles=new ConcurrentDictionary<string, DateTime>();
 
 
-        private readonly AutoResetEvent _pauseAgent = new AutoResetEvent(false);
+        private readonly ManualResetEventSlim _pauseAgent = new ManualResetEventSlim(true);
 
         [System.ComponentModel.Composition.Import]
         public IStatusKeeper StatusKeeper { get; set; }
@@ -84,7 +84,7 @@ namespace Pithos.Core.Agents
                 Action loop = null;
                 loop = () =>
                 {
-                    _pauseAgent.WaitOne();
+                    _pauseAgent.Wait();
                     var message = inbox.Receive();
                     var process=message.Then(Process,inbox.CancellationToken);
                     inbox.LoopAsync(process, loop);
@@ -277,6 +277,7 @@ namespace Pithos.Core.Agents
                 }
                 finally
                 {
+                    //Set the event when all delete actions are processed
                     if (_deleteAgent.InputCount == 0)
                         _pauseAgent.Set();
 
@@ -468,11 +469,14 @@ namespace Pithos.Core.Agents
 
             using (log4net.ThreadContext.Stacks["Retrieve Remote"].Push(accountInfo.UserName))
             {
+                _pauseAgent.Wait();
+
                 Log.Info("Scheduled");
                 var client=new CloudFilesClient(accountInfo);
 
                 var containers = client.ListContainers(accountInfo.UserName);
-                
+
+
                 CreateContainerFolders(accountInfo, containers);
 
                 try