Background process in Asp.Net web application

I have a web app that also has an Android and iPhone app with a centralized database. At some event, I have to perform some database operations from both websites and web services, and also send various SMS, emails and push notifications for Android and iPhone apps (at least 10-15 per time). All these processes take too long and the user needs to wait for the entire operation to complete. To overcome this problem, I implemented a background process (for the first time) that also takes the same amount of time. Please review below code and let me know that I am running the background process correctly or there is some other way to do it.

private readonly BackgroundWorker worker = new BackgroundWorker();

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
 try
 {
   FunctionToBePerformInBackground();    
 }
 catch
 {
 }
}
void Page_Load(object sender, EventArgs e)
{
  worker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
}
protected void buton_click(object sender, EventArgs e)
{
  worker.RunWorkerAsync();
}

      

Thanks in advance...

+3


source to share





All Articles