Click to See Complete Forum and Search --> : How to do Aynchronous programming in a Web application?


Ai _Jun_Zhang
February 24th, 2005, 12:38 PM
I have a page, it has to run for a long time after user click submit. I am thinking about create a new thread or process to do the long run. After the run is finished, the web application is notified. I guess the Asynchronous programming is the solution.

I have searched through the internet, all the solution about asynchronous web application is about Web Service. The application I have is not a Web service and I do not intend to use Web Service as there are some security issues for the reason the a Web Service is automatically exposed.

Please let me know there is any way for a regular web application to do aynchronous programming?

Thanks,

Aijun.

anupam kant
March 7th, 2005, 12:03 AM
yes it is possible to execute program async [although not recommanded]
but I have used it in my page


ThreadStart workerStart = new ThreadStart(ExecFun);
Thread workerThread = new Thread(workerStart);
workerThread.Name = "Carry Forward";
workerThread.Priority = ThreadPriority.AboveNormal;
workerThread.Start();
................
..........

public void ExecFun()
{
.....................
.......................
}



and it is working properly.

hope this helps

Krzemo
March 7th, 2005, 06:40 AM
If it is single call that is blocking main thread, and if U don't need to wait until it finished than U can do "BeginInvoke" to asynchronously call a delegate.

Or use worker thread (u can also use ThreadPool to start it)



workerThread.Priority = ThreadPriority.AboveNormal;
DON'T DO THAT !!!!

Best regards,
Krzemo.

Ai _Jun_Zhang
March 8th, 2005, 11:58 AM
Hi!

I have a question about using Thread. If a page starts a thread, and the user closes the page, is the thread automatically stopped? Or the page has no control the child thread (that is the thread started in the page).

Thanks,

Aijun.

Krzemo
March 8th, 2005, 02:58 PM
If a page starts a thread, and the user closes the page, is the thread automatically stopped? No. All threads will be running until they are killed (or whole process stops) or they finish by themselfs.

Or the page has no control the child thread U have synhronization objects for that (Manual reset event for example)

Best regards,
Krzemo.

PS: Look here for samples:
http://www.c-sharpcorner.com/Multithreading.asp

subdigital
March 19th, 2005, 10:53 PM
if you want to make an asynchronous request to a webservice, there are some builtin methods for that.

If you call Begin_[methodname]() it will fork a thread for you, and all you have to do is setup the delegate to handle the callback when the request is fulfilled.

if you decide at some point you must hang until the request is fulfilled you can call End_[methodname]().

...not sure if this helps, but maybe...