|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sorrow - Can't use semaphore with WebclientTravis,
Unfortunately, it also tells us nothing. How are you using the Semaphore with the WebClient? -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com <jehugalea***@gmail.com> wrote in message news:da1f114a-5cb5-4736-84f8-6b75b68ed204@o6g2000hsd.googlegroups.com... > The title says it all. :-( > > ~Travis There is nothing about the WebClient class that prevents you from using
Semaphore in your code. As Nick indicates, you really haven't told us much. --Peter "Inside every large program, there is a small program trying to get out." http://www.eggheadcafe.com http://petesbloggerama.blogspot.com http://www.blogmetafinder.com Show quote "jehugalea***@gmail.com" wrote: > The title says it all. :-( > > ~Travis > On Nov 29, 5:18 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote: Show quote > There is nothing about the WebClient class that prevents you from using Sorry, I wasn't able to put the code snippet in. I was rushed last> Semaphore in your code. As Nick indicates, you really haven't told us much. > > --Peter > "Inside every large program, there is a small program trying to get out."http://www.eggheadcafe.comhttp://petesbloggerama.blogspot.comhttp://www.blogmetafinder.com > > > > "jehugalea***@gmail.com" wrote: > > The title says it all. :-( > > > ~Travis- Hide quoted text - > > - Show quoted text - night. This is somewhat like what my code looks like: static void Main() { Semaphore semaphore = new Semaphore(1, 1); int i = 0; foreach (WebClient client in GetNextInt()) { semaphore.WaitOne(); client.DownloadFileCompleted += new AsyncCompletedEventHandler( delegate(object sender, AsyncCompletedEventArgs e) { semaphore.Release(); }); client.DownloadFileAsync(new Uri("http:// www.google.com"), @"C:\temp" + i + ".html"); ++i; } } static IEnumerable<WebClient> GetNextInt() { for (int i = 0; i != 10; ++i) { Thread.Sleep(new Random().Next(1000, 5000)); yield return new WebClient(); } } When my code got to the last download, it stopped prematurely. So the last file in this example always had a file of 0 bytes. Which means my application is stopping even though there are downloads currently in progress. I would have thought a thread would have prevented that. Is there anyway to prevent this? By the way, I thought my application wasn't working at all last night because I only had one Web Client. |
|||||||||||||||||||||||