Can one thread see that the other one's dead?
-
I have two theads in my windows app- the main GUI thread, and a constantly listening worker which runs an infinite while(true) loop. The problem is, when I quit the app, the worker thread keeps running and sucks up 100% CPU time. So, I have the main gui thread set a bool variable to false when the app's window closes, and then in the loop for the worker, it listens for that and kills itself when it sees that the bool is false. That's all fine, but my fear is what if the main window of the app gets blown up, and it's "window closing" event never fires? Like, if the main window is closed because it throws some low level error or something. I've seen it happen already. In that case, the worker thread would never get the signal to die. Is there some other way to make the worker check on the existence of the gui thread? thanks "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx
-
I have two theads in my windows app- the main GUI thread, and a constantly listening worker which runs an infinite while(true) loop. The problem is, when I quit the app, the worker thread keeps running and sucks up 100% CPU time. So, I have the main gui thread set a bool variable to false when the app's window closes, and then in the loop for the worker, it listens for that and kills itself when it sees that the bool is false. That's all fine, but my fear is what if the main window of the app gets blown up, and it's "window closing" event never fires? Like, if the main window is closed because it throws some low level error or something. I've seen it happen already. In that case, the worker thread would never get the signal to die. Is there some other way to make the worker check on the existence of the gui thread? thanks "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx
On your worker thread, set the
IsBackground
property totrue
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
On your worker thread, set the
IsBackground
property totrue
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks, it turns out that the worker thread is not my problem after all. My problem is much deeper and more anoying. So much so that I'll make a whole new post about it. thanks, "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx