S
Steve B.
Hi,
I'd like to know what is the difference between the class AutoResetEvent and
ManualResetEvent.
Actually, I want to use the WebClient.DownloadString method to download 8
files simultaneously in order to concatenate the content of the 8 files (no
matter in which order).
How can I do that ?
What are the available class to reach my goal ?
Is this code snippet the best way ?
StringBuilder sb;
public void Do(string[] urls)
{
WebClient wc = new WebClient();
sb = new StringBuilder();
wc.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
AutoResetEvent[] threadSync = new AutoResetEvent[urls.Length];
for (int i = 0; i < urls.Length; i++)
{
threadSync = new AutoResetEvent(true);
wc.DownloadStringAsync(
new Uri(urls),
are
);
}
foreach (AutoResetEvent are in threadSync)
{
are.WaitOne();
}
context.Response.ContentType = "text/css";
}
private void wc_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
lock (sb)
{
sb.AppendLine(e.Result);
}
((AutoResetEvent)e.UserState).Set();
}
Thanks in advance,
Steve
I'd like to know what is the difference between the class AutoResetEvent and
ManualResetEvent.
Actually, I want to use the WebClient.DownloadString method to download 8
files simultaneously in order to concatenate the content of the 8 files (no
matter in which order).
How can I do that ?
What are the available class to reach my goal ?
Is this code snippet the best way ?
StringBuilder sb;
public void Do(string[] urls)
{
WebClient wc = new WebClient();
sb = new StringBuilder();
wc.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
AutoResetEvent[] threadSync = new AutoResetEvent[urls.Length];
for (int i = 0; i < urls.Length; i++)
{
threadSync = new AutoResetEvent(true);
wc.DownloadStringAsync(
new Uri(urls),
are
);
}
foreach (AutoResetEvent are in threadSync)
{
are.WaitOne();
}
context.Response.ContentType = "text/css";
}
private void wc_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
lock (sb)
{
sb.AppendLine(e.Result);
}
((AutoResetEvent)e.UserState).Set();
}
Thanks in advance,
Steve