Silverlight-sequential execution of multiple asynchronous calls, silverlight asynchronous

Source: Internet
Author: User

Silverlight-sequential execution of multiple asynchronous calls, silverlight asynchronous

If you encounter such a functional requirementSame ServiceIt is called multiple times, but the input parameter must be executed after another execution.

Because silverlight supportsAsynchronous callTherefore, it is impossible to control when a service call is returned. What if the call sequence of the parameter queue is executed?

After thinking for one night, I came up with a compromise.Recursion.

 1        ObservableCollection<taskVO> ocTask = new ObservableCollection<taskVO>(); 2         taskVO currentTask; 3         int len = 0,index = 0; 4         private void btn_click(object sender , RoutedEventArgs e){ 5              6            if(ocTask == null) { 7                return; 8            } 9            len = ocTask.Count();
11 currentTask = ocTask[index]; 12 13 index++;14 client.methodAsync(currentTask);15 }16 17 void client_methodCompleted(object sender , CompletedEventArgs e){
21 22 if(index >= len) 23 {24 return;25 }26 currentTask = ocTask[index];27 index++;28 client.methodAsync(currentTask);31 }

OcTask is a parameter queue for multiple asynchronous calls.

In a button event, only the first Task is called asynchronously. In the callback function, the next Task is called asynchronously, and so on until the last parameter is completed, return in Completed and end recursion (this is the final condition that the recursive function learned in the textbook must have. The first time the algorithm in the book is applied to the actual situation, it is better to enable the kaison kaosen ^_^)

PS:

Solving this function does not solve the real asynchronous queue sequence call problem. This feature is special. Multiple asynchronous calls use the same method, which causes recursion to solve this problem.

However, the limitations of recursion also limit that asynchronous queues cannot be too long. Otherwise, recursive stack overflow occurs. Therefore, this problem still needs to be improved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.