开发者

Silverlight sequential operation for Asynchronous operation

I have 3 operation that need to process sequentially, they are

  1. GetMainInformation
  2. GetDetails1
  3. GetDetails2

I'm doing this by code like below but I think it isn't clean. I w开发者_StackOverflowant to know an alternative way to do async operation in sequential order.

GetMainInformation.Completed += GetDetails1;
GetDetails1.Completed += GetDetails2;


You could create a queue. Something like this:

GetMainInformation.Completed += GetMainInformationCompleted
GetDetails1.Completed += GetDetails1Completed
GetDetails2.Completed += GetDetails2Completed

Start the request:

requestCounter = 3;
GetMainInformationAsync();
GetDetails1();
GetDetails2();

In each one of the completed functions:

void GetMainInformationCompleted()
{
  // Store result in member variable
  requestCounter--;
  if (requestCounter == 0)
  {
    ProcessRequest();
  }
}


You can use Caliburn Micro's IResult and Coroutines. How to ensure all properties have loaded in Silverlight ViewModel pattern (Concurrency Control?)


If the code must run in a specific order, and sequentially, why not have Getdetails2, called in the oncompletion of GetDetails1, etc so it works its way through? Or. Have your service have a function to call all 3, if the data is related, it maybe feasible to have a data structure with lists/arrays within it such as.

   String CustomerName, 
String Address, 
String PhoneNumber, 
List<orders> Orders, 
List<itemsMarked> ItemsMarked

Where the MainInfo goes to the customer parts, the details1 goes into orders and details2 into marked items etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜