OutProc on State Server: Thread problem
-
Hi folks, I am new to ASP.Net development as such, so my questions can be really stupid. Thanks a ton in advance and pointers greately appreciated The problem: For Web Farm setup, we are trying to keep the session data in State Server. We have marked the objects as [Serializable] to make them fit in State Server. Now, we keep some of the data bjects in session and we are also keeping threads that operate on these objects in session. The class looks like: [serializable] Class DataManager { Data1 data1Obj; Data2 data2Obj; [nonserialized]Thread m_thread; [nonserialized]AutoResetEvent m_event; [nonserialized]Thread m_updateThread; ..... } Now we are getting exception as threads and events are non-serializable when we run the program. We added the attribute [nonserialized] to these individual thread variables and events. But the strange thing is, once we allocate the threads and start them, some how the thread objects are set to null. I guess this happens after one serialization operation. So imaginge, the program is continuously stuck on checking the thread null and allocating it again. This obviously is not working at all. // the code looks like void somefunction() { if (m_thread == null) { RespawanThread() // this happens all the time } } My question is even after adding the [nonserialized] tag to the individual thread members, what makes them null after some time?
Evil triumphs when good people sit quiet...
-
Hi folks, I am new to ASP.Net development as such, so my questions can be really stupid. Thanks a ton in advance and pointers greately appreciated The problem: For Web Farm setup, we are trying to keep the session data in State Server. We have marked the objects as [Serializable] to make them fit in State Server. Now, we keep some of the data bjects in session and we are also keeping threads that operate on these objects in session. The class looks like: [serializable] Class DataManager { Data1 data1Obj; Data2 data2Obj; [nonserialized]Thread m_thread; [nonserialized]AutoResetEvent m_event; [nonserialized]Thread m_updateThread; ..... } Now we are getting exception as threads and events are non-serializable when we run the program. We added the attribute [nonserialized] to these individual thread variables and events. But the strange thing is, once we allocate the threads and start them, some how the thread objects are set to null. I guess this happens after one serialization operation. So imaginge, the program is continuously stuck on checking the thread null and allocating it again. This obviously is not working at all. // the code looks like void somefunction() { if (m_thread == null) { RespawanThread() // this happens all the time } } My question is even after adding the [nonserialized] tag to the individual thread members, what makes them null after some time?
Evil triumphs when good people sit quiet...
You can't keep a thread active in session. When you store data in session, you are simply saving XML in memory. Your class is written out as XML and then when you deserialize it, a new instace is created and the values of properties are retreived from the XML. Also, from my experience, you do not want to keep a thread alive between postbacks. It is a bad idea. The reason being is that the client can abrubtly disconnect and it is not always possible to fire an event in your server code when that happens.
I didn't get any requirements for the signature