Click here to Skip to main content
13,000,742 members (55,140 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a function which performs a series of time-consuming operations which include querying a large database, customising an excel file and sending an email with a 5MB attachment.
I would like to excute this function in the background, when a button is clicked, and immediately redirect the user to another aspx page. The user should be free to browse to other pages or even close the browser when the background operation is still running on the server.
I have tried to implement threading but could not get it to work. The email with attachment does not get sent even though there are no errors.

The code I have used is :
protected void Button1_Click(object sender, EventArgs e)
        string OrderNo = obj_CustomerInfo.OrderNo;
        string CustomerFilePath = XLFile;
        object[] parameters = new object[] { OrderNo,CustomerFilePath };
        Thread FDthread = new Thread(new ParameterizedThreadStart(ProcessingOps));
        FDthread.IsBackground = true;
private static void ProcessingOps(object parameters)
         object[] parameterArray = (object[])parameters;
         string OrderNo = (string)parameterArray[0];
         string CustomerFilePath = (string)parameterArray[1];
         // Time consuming operations....
I would be very gratefull for any help or guidance as to how to achieve this.

Thanks and Regards
Posted 28-Oct-10 1:45am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Threads don't work as you would expect under
What you are better off doing is placing the work to be done in a database table as a queue and having another program such as a windows service go through that queue and do the processing.
What you return to the user is a message that their request has been added to the queue for processing, you may also want to have another page where the user can check the progress of the processing queue to see when their request has been processed but this is optional depending on requirements.
Sandeep Mewara 28-Oct-10 12:46pm
Comment from OP:
Hi Rod,

Thanks for the reply.
The application am working on is hosted in a shared server. Would it be possible for me to implement a Windows Service in a such a case? Would it require any software installments on the server or specific permissions to get this to work?

Rod Kemp 28-Oct-10 20:36pm
In the case of a shared server it is up to the people that manage the server so you would need to talk to them.
As for what is required have a look at BugTracker.Net the service this has receives email but you can change that to send email instead. The installation requirements are under in the documentation under "Receiving email using btnet_service.exe" also look at the code in the btnet_service.cs file.
Rod Kemp 28-Oct-10 20:37pm
If going down the road of a windows service doesn't work have a look at
kavya_m_82 29-Oct-10 2:21am
Thank you once again. I shall verify is it is possible to use a windows service and also go through the link on how to use AsyncTasks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 28 Oct 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100