From 6a8aa83390cb2e8d8b944bf3a1f423add79312d9 Mon Sep 17 00:00:00 2001 From: Panagiotis Kanavos Date: Fri, 17 Feb 2012 17:02:19 +0200 Subject: [PATCH] Changed AsyncManualResetEvent.Set behaviour to occur asynchronously. In the previous version calling Set resulted in the poll method executing in the main thread --- trunk/Pithos.Core/Agents/AsyncManualResetEvent.cs | 8 +++++++- trunk/Pithos.Core/Agents/NetworkAgent.cs | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/trunk/Pithos.Core/Agents/AsyncManualResetEvent.cs b/trunk/Pithos.Core/Agents/AsyncManualResetEvent.cs index 00ec851..c0e621f 100644 --- a/trunk/Pithos.Core/Agents/AsyncManualResetEvent.cs +++ b/trunk/Pithos.Core/Agents/AsyncManualResetEvent.cs @@ -39,7 +39,13 @@ namespace Pithos.Core.Agents _tcs.Task.Wait(); } - public void Set() { _tcs.TrySetResult(true); } + public void Set() + { + var tcs = _tcs; + Task.Factory.StartNew(s => ((TaskCompletionSource)s).TrySetResult(true), + tcs, CancellationToken.None, TaskCreationOptions.PreferFairness, TaskScheduler.Default); + tcs.Task.Wait(); + } public void Reset() { diff --git a/trunk/Pithos.Core/Agents/NetworkAgent.cs b/trunk/Pithos.Core/Agents/NetworkAgent.cs index 72ae3c5..93bbcfc 100644 --- a/trunk/Pithos.Core/Agents/NetworkAgent.cs +++ b/trunk/Pithos.Core/Agents/NetworkAgent.cs @@ -343,6 +343,8 @@ namespace Pithos.Core.Agents //Remote files are polled periodically. Any changes are processed public async Task PollRemoteFiles(DateTime? since = null) { + Debug.Assert(Thread.CurrentThread.IsBackground,"Polling Ended up in the main thread!"); + UpdateStatus(PithosStatus.Syncing); StatusNotification.Notify(new PollNotification()); -- 1.7.10.4