I have a web application and in the code behind page, I have a button click event.
protected void btnUpload_Click(object sender, EventArgs e)
{
TimerEvent TE = new TimerEvent();
TE.TimerEvents();
Server.Transfer("~/Jobs.aspx");
}
I am having a method call TimerEvents() and it may take 10-15 seconds to get the control back to the server transfer. so I want the server transfer line to be executed simultaneously at the same time of the method call.
I tried threading as in here:
TimerEvent TE = new TimerEvent();
Thread t = new Thread(TE.TimerEvents);
t.IsBackground = true;
t.Start();
Server.Transfer("~/Jobs.aspx");
But the transfer is not made, until the method is finished. How can I achieve this?
This design is not ideal. Even if you get it right, there's a chance you'll run into problems down the road due to the mixing of multi-threading code and the Server.Transfer() call.
There are also issues regarding multi-threading in ASP.NET applications.
I suggest you re-engineer your app so that you have some kind of queue that queues up long-running tasks. You can then then have a service that processes tasks in the queue one by one.
From your web application, you'll now be able to:
Queue up the long running TimerEvents task to the external service.
Call Server.Transfer()
On the new page ("~/Jobs.aspx"), call the external service to pick up your results when you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With