This is the scenario. I have a webpage called ClientPage . When user clicks on a button in ClientPage, 2 things happen-
1) A thread is called which runs a function. Lets call it thread1.
2) The user is directed to a WaitPage where a animation is played. Meanwhile thread1 keeps running.
When thread1 is done, the WaitPage is automatically supposed to know that and redirect the user to another page. How can I achieve this?
My plan was for ClientPage to store a session variable ->
Session["State"]="Started";
Then the WaitPage would start a thread, lets say thread2, which would keep checking the status of
Session["State"]
. When thread1 is done, it would update
Session["State"]
status to "Completed". Then the WaitPage would know and redirect user to appropriate new page.
My problem right now is that session variables cannot be accessed by threads properly. Even if I pass the current HttpContext to the thread, the thread is unable to access it because the original HttpContext expires soon after the thread is called. I cannot hold on the original HttpContext because my WaitPage needs to keep loading. To people who do not know what I am talking about, look at code below. I am talking about doing something as shown below in WaitPage->
private void Page_Load(object sender, System.EventArgs e)
{
current_context = HttpContext.Current;
timer1.Interval = 2000;
CallNewThreadwithParameter(current_context);
}
NewThread(HttpContext context)
{
HttpContext newcontext = context;
if(newcontext.Session["State"].ToString()=="Completed")
{
}
}
So as shown above this does not work.
I cannot also do something like below in my WaitPage because then the Wait Page would never load->
private void Page_Load(object sender, System.EventArgs e)
{
current_context = HttpContext.Current;
timer1.Interval = 2000;
CallNewThreadwithParameter(current_context);
while( current_context[Session]=="Started" )
{
}
}
How can I achieve what I want to do? Can you help me out?
If you do not understand what I am trying to achieve, please let me know what exactly you dont understand and I will try improve my question.
Thanks
Jobin