Asynchronous processing in ASP.Net using delegate

There are times when we need to get the control of the UI after telling the server to do something, i.e. Bulk upload.  The example below uses delegate to return the control after extracting a large file:

public delegate string ExtractFile(Stream fs);

public void Run(Stream fs)
{
ExtractFile ef = new ExtractFile(ProcessFile);
ef.BeginInvoke(fs, new AsyncCallback(ProcessFileEnd), ef);
}
private string ProcessFile(Stream fileStream)
{
string message = DoSomething();

return message;
}

void ProcessFileEnd(IAsyncResult result)
{
ExtractFile ret = result.AsyncState as ExtractFile;

string message = ret.EndInvoke(result);
}

Notice that I use AsyncCallback when calling the beginInvoke. This can be used if we want to do something after the long task. However I haven’t found a good way to update the UI in ASP.Net -_-

One Response to Asynchronous processing in ASP.Net using delegate

  1. Charu says:

    Thank you so much for the post……..saved my time 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: