Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can one thread see that the other one's dead?

Can one thread see that the other one's dead?

Scheduled Pinned Locked Moved C#
helpquestionlearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bog
    wrote on last edited by
    #1

    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

    Richard DeemingR 1 Reply Last reply
    0
    • B Bog

      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

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      On your worker thread, set the IsBackground property to true.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      B 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        On your worker thread, set the IsBackground property to true.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        B Offline
        B Offline
        Bog
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups