Pages

Wednesday, September 11, 2013

Async function Call on button click or page load

public delegate string LoadDelegateR(string userName, string reportingDate, Dictionary<string, string> functions, string jobNumber, out string message);

protected void Page_Load(object sender, EventArgs e)
{
 // call asynchronously                       
 LoadDelegateR d = new LoadDelegateR(ImportData);
 d.BeginInvoke(user, txtPeriod.Text.Trim(), functions, txtJobNumber.Text.Trim(), out message, new System.AsyncCallback(SendNotification), null);
}

public override string ImportData(string username, string reportingDate, Dictionary<string, string> functions, string jobNumber, out string message)
{
}

public void SendNotification(IAsyncResult iRes)
{
 try
 {
  AsyncResult ar = (AsyncResult)iRes;
  LoadDelegateR bp = (LoadDelegateR)ar.AsyncDelegate;
  string result = bp.EndInvoke(out message, iRes);
 }
 catch (Exception ex)
 {
  message = "Error in loading the data.Please contact admin.";
 }
}

No comments:

Post a Comment