Last post Sep 17, 2010 12:26 PM by bradwoody
Nov 17, 2009 03:35 AM|eitama|LINK
I have a page named Calculate.ashx, the page will be called every 10 seconds until a complete result is available.
I need to start 3 external applications, each to fetch information for me, the whole thing would take about 3 minutes.
My question is, how do I start 3 threads and "keep in touch" with them from the ashx code, even though the context of the file will end
because I have to send a response to client?
I'm not sure I am clear so i'll try to explain it again in a different way,
when a request arrives to Calculate.ashx for the 1st time, Calculate.ashx will start 3 Threads, each with it's own job.
Now i need to answer the client with ResponseWrite or something, and the ashx file flow will end.
In 10 seconds, the client will again send a request to Calculate.ashx, now Calculate.ashx needs to check the state of the Threads it created 10 seconds ago,
Will these Threads still exist? won't they be deleted because the context ended 10 seconds ago?
How do I keep the "pointers" to those Threads?
Nov 17, 2009 07:28 AM|docluv|LINK
My advice is to leverage AJAX to make the call. This will allow you to spin up your threads on the server and wait for all of them to return without tying up you client-interface.
I would use the AJAX features of JQuery because they are so easy to work with.
Nov 17, 2009 08:08 AM|eitama|LINK
Thank you for your response,
My problem is not really on the client side, using Ajax might make thing prettier for the client expirience, but right now I am worried with how to allow the server to answer
HTTP Requests (GET) while the threads work without the threads closing - I simply don't know which approach i should take.
Lets say I have a "DoSomething.ashx" file which starts 3 Threads to execute external applications, I start the apps, and redirect the user to "WaitForResult.aphx" file.
Now the user sends a request to the new page, and he gets a complete result only when the Threads finish, How do I check the Threads status? do they stay alive even though "DoSomething.ashx"
has finished it's role?
Sep 17, 2010 12:26 PM|bradwoody|LINK
Yours is a difficult problem to describe. I know because I had the same issue and I asked everyone I knew, but no one understood web programming or could not envision my requirements. Your connections to the threads go away once you present the page to
I ended up creating a 'helper' table in a database and writing messages to it from the master thread and the spawned threads. These messages (in your case) could include the calculated results and stop commands. Any thread (master or spawned) can read
the messages and react accordingly.
In the event you have no database available you can do the same with one or more files in the web server's file system.
It could be argued that these database calls are unnecessary or writing to the file system is too slow. But, as my boss says, "it is what it is". And since your app has 10-second delays anyway, the few milliseconds to access the db or the file system are
I'm sure there are other solutions, but I scoured the web and found nothing workable.
I hope that helps the next programmer who reads this post...