Question Problems with Thread + Invoke + Abort / Join

wellhole

New member
Joined
Dec 8, 2009
Messages
2
Programming Experience
1-3
I'm trying to make it so a user enters a query on a form, hits the database, and displays the results. This is relatively easy without threads, but I'm trying to make the form responsive. So, the thread will send query, receive results, and Invoke() to fill out the form (since you cant change main thread controls from another thread).

The problem I'm running into is that if the first query is interrupted by a second query, the form *may* freeze completely. This happens when I use Abort() from the main thread while the first query's thread is accessing the form controls.

I also tried using a member variable to indicate to the thread that it should exit and then run Join() afterwards, and it seems to get stuck at the same places where its invoking and accessing form controls.

Edit: Ahah! After a lot of digging and testing, I was able to use a boolean indicator and on main thread --> while thread.IsAlive { app.DoEvents }. This seems to let the main thread run Invoke() from the child thread. (This is just how I'm making sense of it...) I couldn't make it work when I used thread.Abort(). Any ideas?
 
Last edited:
Back
Top