Thread ending problem in CFormView
-
Hi, I have a CFormView derived class which has a thread running at the background which does some background processing. On my view, I have a button which when clicked, the handler function gets called and takes the user to some other screen. When clicked on the button, I cannot wait till my background thread ends and then call the handler. I have to immediately call the handler function without waiting for the thread to end. What I am doing presently is, just signaling an event to end the thread and call the handler without waitng for he thread to end. if I do this way,my program is crashing with an assertion(it says illegal access of members in the thread). Inside the thread, members of the CFormView derived class are used. Can anyone please suggest me a solution to call the handler immediately, without waiting for the thread to end and at the same time my program should not crash. Thanks Madhavi.
-
Hi, I have a CFormView derived class which has a thread running at the background which does some background processing. On my view, I have a button which when clicked, the handler function gets called and takes the user to some other screen. When clicked on the button, I cannot wait till my background thread ends and then call the handler. I have to immediately call the handler function without waiting for the thread to end. What I am doing presently is, just signaling an event to end the thread and call the handler without waitng for he thread to end. if I do this way,my program is crashing with an assertion(it says illegal access of members in the thread). Inside the thread, members of the CFormView derived class are used. Can anyone please suggest me a solution to call the handler immediately, without waiting for the thread to end and at the same time my program should not crash. Thanks Madhavi.
ledallam wrote:
Can anyone please suggest me a solution to call the handler immediately, without waiting for the thread to end and at the same time my program should not crash.
How do you grant access to the CFormViews member variables in the first place and how do you spawn your thread? When you call the so called "handler", what does it mean? Is the CFormView object destroyed when you call the "handler"? One solution could be to make sure it's not. -- Roger
It's supposed to be hard, otherwise anybody could do it!
-
Hi, I have a CFormView derived class which has a thread running at the background which does some background processing. On my view, I have a button which when clicked, the handler function gets called and takes the user to some other screen. When clicked on the button, I cannot wait till my background thread ends and then call the handler. I have to immediately call the handler function without waiting for the thread to end. What I am doing presently is, just signaling an event to end the thread and call the handler without waitng for he thread to end. if I do this way,my program is crashing with an assertion(it says illegal access of members in the thread). Inside the thread, members of the CFormView derived class are used. Can anyone please suggest me a solution to call the handler immediately, without waiting for the thread to end and at the same time my program should not crash. Thanks Madhavi.
We solved a problem similar to this by placing the thread control information into a separate queue. The queue is a singleton at the 'applciaiton' level,a nd not controlled by any of the threads' clients. The thread and the thread's client could access the thread data via the queue. If the 'client' had to leave before the thread was done, then the thread was signaled to exit, but it became a 'zombie' thread and removed itself from the qeue when it could. This way, there was no access violation because the thread's data belonged to a client that might 'disappear' before the thread was done.