[hyena] [HttpDownloder] Add StartSync method



commit 5893445a7e2c1aa00967d6b66a72e0c794375d7f
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Jul 14 10:32:19 2010 -0700

    [HttpDownloder] Add StartSync method

 Hyena/Hyena.Downloader/HttpDownloader.cs |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/Hyena/Hyena.Downloader/HttpDownloader.cs b/Hyena/Hyena.Downloader/HttpDownloader.cs
index a9026b7..e2d722f 100644
--- a/Hyena/Hyena.Downloader/HttpDownloader.cs
+++ b/Hyena/Hyena.Downloader/HttpDownloader.cs
@@ -27,6 +27,7 @@
 using System;
 using System.IO;
 using System.Net;
+using System.Threading;
 
 namespace Hyena.Downloader
 {
@@ -42,6 +43,7 @@ namespace Hyena.Downloader
         private Stream response_stream;
         private DateTime last_raised_percent_complete;
         private IAsyncResult async_begin_result;
+        private ManualResetEvent sync_event;
 
         public string UserAgent { get; set; }
         public Uri Uri { get; set; }
@@ -76,6 +78,14 @@ namespace Hyena.Downloader
             ProgressEventRaiseLimit = TimeSpan.FromSeconds (0.25);
         }
 
+        public void StartSync ()
+        {
+            sync_event = new ManualResetEvent (false);
+            Start ();
+            sync_event.WaitOne ();
+            sync_event = null;
+        }
+
         public void Start ()
         {
             lock (SyncRoot) {
@@ -263,6 +273,10 @@ namespace Hyena.Downloader
             if (handler != null) {
                 handler (this);
             } 
+
+            if (sync_event != null) {
+                sync_event.Set ();
+            }
         }
 
         public override string ToString ()
@@ -270,4 +284,4 @@ namespace Hyena.Downloader
             return Name;
         }
     }
-}
\ No newline at end of file
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]