How to communicate a aspx page with a thread ( one thread per session )? I try to build a thread that be able to communicate with a aspx (C#). Basically, this thread launches a special procedure which can take several minutes. Also, the aspx page refreshes
automatically every 5s(meta http-equiv=refresh content="1,qsdf.aspx”) and it shows the status like a progress bar. Currently, I can launch and execute a separate thread in my Web Sessio n. But I could not communicate by event and collection class. For example.
In my main aspx,I create a new instance of my Collection(ArrayList) (private list { set{ Session[“List”] } get{return (LIST)Seesion[“ref”] }}). In my constructor thread, I take this List(ref) to pass like parameter. But apparently my collection has not been
modified by my thread when I try to read that in my aspx page. Could you help me? Where can I find some documentation about that? Thank in advance ….. Bye bye Ps=the thread is saved in the session variable
In order to ensure that data is indeed ready when UI (aspx) thread reads them, you must synchronize threads. Otherwise UI thread may be reading data too early. The simplest possible case is a boolean flag that background thread sets when it is done. UI thread
checks the flag periodically, waiting for data to be ready. However, looping wastes CPU cycles. Typically you create an event object on which UI thread waits until background thread signals that it is done. When the event is signaled, UI thread gets unblocked
and can safely access the data. In your case, however, this may not work, since you want UI thread to report progress (hence it cannot be blocked waiting for an event). UI thread may put itself to sleep for a second or so, then wake up, check the signal, report
progress and go back to sleep if data is still not ready. Heave a look here
Synchronizing Data for Multithreading
zoltix
Member
42 Points
9 Posts
How to communicate a aspx page with a thread ( one thread per session )?
Sep 01, 2003 10:01 PM|LINK
Mikhail Arkh...
All-Star
33139 Points
6083 Posts
Microsoft
Re: How to communicate a aspx page with a thread ( one thread per session )?
Sep 02, 2003 04:22 AM|LINK
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.