开发者

Multitasking and Multithreading in silverlight

I have a silverlight application in which i have multiple requests that goes to the server.I want that all these request to be syn开发者_Go百科chronized i.e by means of queue or by means of multitasking.What is the best mean of doing so.Plz provide some example in silverlight where io could do so.


Take a look at the ASYNC CTP Framework: http://msdn.microsoft.com/en-us/vstudio/gg316360

It offers easy ways to handle / synchronize async requests, like the following sample:

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"));
}

or

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));
    }
}

The classic way is to use WaitHandles like the AutoResetEvent to synchronize requests.


Reactive Extensions could also be a valid option. This is a good article that shows using it for asynchronous calls to a WCF service.


The point is that you can't control the order of the request, and by defaults you only can make two requests to the same domain, so it's means that you need to build something on the client in order to send requests in the order you want to be executed, and of course Silverlight only supports BasicHttpBinding means you haven't got the ordered message property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜