--- /dev/null
+// -----------------------------------------------------------------------\r
+// <copyright file="AsyncManualResetEvent.cs" company="Microsoft">\r
+// TODO: Update copyright text.\r
+// </copyright>\r
+// -----------------------------------------------------------------------\r
+\r
+using System.Threading;\r
+using System.Threading.Tasks;\r
+\r
+namespace Pithos.Core.Agents\r
+{\r
+ using System;\r
+ using System.Collections.Generic;\r
+ using System.Linq;\r
+ using System.Text;\r
+\r
+ /// <summary>\r
+ /// TODO: Update summary.\r
+ /// </summary>\r
+ public class AsyncManualResetEvent\r
+ {\r
+ private volatile TaskCompletionSource<bool> _tcs;\r
+\r
+ public AsyncManualResetEvent()\r
+ {\r
+ _tcs = new TaskCompletionSource<bool>();\r
+ }\r
+\r
+ public AsyncManualResetEvent(bool signalled)\r
+ { \r
+ _tcs = new TaskCompletionSource<bool>();\r
+ if (signalled)\r
+ _tcs.SetResult(true);\r
+ }\r
+ public Task WaitAsync() { return _tcs.Task; }\r
+\r
+ public void Wait()\r
+ { \r
+ _tcs.Task.Wait();\r
+ }\r
+\r
+ public void Set() { _tcs.TrySetResult(true); }\r
+\r
+ public void Reset()\r
+ {\r
+ while (true)\r
+ {\r
+ var tcs = _tcs;\r
+ if (!tcs.Task.IsCompleted ||\r
+ Interlocked.CompareExchange(ref _tcs, new TaskCompletionSource<bool>(), tcs) == tcs)\r
+ return;\r
+ }\r
+ }\r
+ }\r
+}\r
readonly ConcurrentDictionary<string,DateTime> _deletedFiles=new ConcurrentDictionary<string, DateTime>();
- private readonly ManualResetEventSlim _pauseAgent = new ManualResetEventSlim(true);
[System.ComponentModel.Composition.Import]
public IStatusKeeper StatusKeeper { get; set; }
public IPithosSettings Settings { get; set; }
private bool _firstPoll = true;
+
private TaskCompletionSource<bool> _tcs;
- private ConcurrentDictionary<string,DateTime> _lastSeen=new ConcurrentDictionary<string, DateTime>();
+ private readonly AsyncManualResetEvent _pauseAgent = new AsyncManualResetEvent(true);
+
+ private ConcurrentDictionary<string, DateTime> _lastSeen = new ConcurrentDictionary<string, DateTime>();
public void Start()
{
using (log4net.ThreadContext.Stacks["Retrieve Remote"].Push(accountInfo.UserName))
{
- _pauseAgent.Wait();
+ await _pauseAgent.WaitAsync();
Log.Info("Scheduled");
var client = new CloudFilesClient(accountInfo)
try
{
- _pauseAgent.Wait();
+ await _pauseAgent.WaitAsync();
//Get the poll time now. We may miss some deletions but it's better to keep a file that was deleted
//than delete a file that was created while we were executing the poll
var pollTime = DateTime.Now;