I want to call number of methods asynchronously but each method should execute after completion of previous method.
Till now I was wrapped all method under one Master method and called it(Master Method) asynchronously using delegate. now requirement has changed and method which called sequentially in side master method may or may not be called depend on different status. I can achieve it with current architecture by checking different permutation and combination. but I want to execute each method asynchronously but sequentially
This is my current Implementation which run asynchronously (Note: this is an sample code to describe my functionality)
Function 1
private void SaveCustomer(List<Customer> customers)
{
// Doing some calculation and saving customer in database
}
Function 2
private decimal CalulateRate(RateInfo applicableRate)
{
// Calculate rate and some other factors and save in database
}
Function 3
GenerateInvoice(decimal calculatedRate,DateTime effectiveDate,
Int32 NumberOfDays)
{
// generating invoice and saving in database
}
Function 4
GenerateCustomerDocuments(List<DocumentInfo> documentsToGenerate,
List<Customer> customers)
{
// generating diffrent documents for customers
}
I am calling all above function sequentially from one master Method asynchronously
Private void ExecuteCustomerRegistration(CustomerRegInfo custRegInfo)
{
//CustomerRegInfo is a class which contains all input parameter
object for below methotds
SaveCustomer(custRegInfo.Customers);
decimal rate = CalulateRate(custRegInfo.ApplicableRate);
GenerateInvoice(rate,custRegInfo.EffectiveDate,custRegInfo.NumberOfDays);
GenerateCustomerDocuments(custRegInfo.DocumentsToGenerate,
documentsToGenerate.Customers)
}
Calling ExecuteCustomerRegistration method asynchronously using delegate
protected delegate void delg_DoProcess(CustomerRegInfo custRegInfo);
protected void btnRegisterCustomer_Click(object sender, EventArgs e)
{
delg_DoProcess doProc = new delg_DoProcess(ExecuteCustomerRegistration);
CustomerRegInfo custRegInfo = GetCustomersRegInfo();
doProc.BeginInvoke(custRegInfo, null, null);
}
I want to do same job asynchronously for each methods which are under ExecuteCustomerRegistration method like this
- Call SaveCustomer asynchronously
- On completion of SaveCustomer call CalulateRate asynchronously
- On completion of CalulateRate call GenerateInvoice asynchronously
- On completion of GenerateInvoice call GenerateCustomerDocuments asynchronously
Please suggest me how can I do it. currently I am using .net 4.0