Silverlight中的多任务处理和多线程处理

Tar*_*run 5 asp.net silverlight wcf silverlight-3.0

我有一个silverlight应用程序,其中有多个请求进入服务器.我希望所有这些请求同步,即通过队列或多任务处理.这样做的最佳方法.Plz提供了一些示例在银光中,io可以这样做.

小智 0

看一下 ASYNC CTP 框架: http://msdn.microsoft.com/en-us/vstudio/gg316360

它提供了处理/同步异步请求的简单方法,如以下示例:

public async void AsyncWebRequestGetResponse()
{
    var response = await WebRequest.Create("http://www.weather.gov").GetResponseAsync();
    var stream = response.GetResponseStream();
    Console.WriteLine("First byte: {0}", stream.ReadByte().ToString("X2"));
}
Run Code Online (Sandbox Code Playgroud)

或者

public async void AsyncForEach()
{
    var uris = new List<Uri> { new Uri("http://www.weather.gov"), new Uri("http://www.weather.gov/climate/"), new Uri("http://www.weather.gov/rss/") };

    foreach (var uri in uris)
    {
        WriteLinePageTitle(await new WebClient().DownloadStringTaskAsync(uri));
    }
}
Run Code Online (Sandbox Code Playgroud)

经典的方法是使用像 AutoResetEvent 一样的 WaitHandles 来同步请求。