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. Another Threading Question

Another Threading Question

Scheduled Pinned Locked Moved C#
questioncsharp
3 Posts 3 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.
  • N Offline
    N Offline
    NameYou
    wrote on last edited by
    #1

    In C#, how does one make a thread live indefinitely? MyObject obj = new MyObject(); Thread t = new Thread(new ThreadStart(obj.MyMethod)); t.Start(); Because MyMethod has code in it that kicks off an asynchronous process in it, I want that thread to live forever (or at least until the application is terminated). Any ideas on how that might be accomplished? Thank you, Dan

    C#, King of languages

    G V 2 Replies Last reply
    0
    • N NameYou

      In C#, how does one make a thread live indefinitely? MyObject obj = new MyObject(); Thread t = new Thread(new ThreadStart(obj.MyMethod)); t.Start(); Because MyMethod has code in it that kicks off an asynchronous process in it, I want that thread to live forever (or at least until the application is terminated). Any ideas on how that might be accomplished? Thank you, Dan

      C#, King of languages

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Just don't return from the method.

      --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

      1 Reply Last reply
      0
      • N NameYou

        In C#, how does one make a thread live indefinitely? MyObject obj = new MyObject(); Thread t = new Thread(new ThreadStart(obj.MyMethod)); t.Start(); Because MyMethod has code in it that kicks off an asynchronous process in it, I want that thread to live forever (or at least until the application is terminated). Any ideas on how that might be accomplished? Thank you, Dan

        C#, King of languages

        V Offline
        V Offline
        Vega02
        wrote on last edited by
        #3

        Guffa had the right answer. But just to clarify, the thread won't end until the method obj.MyMethod() returns. You're allowed to return from the method that creates the Thread object and calls t.Start(). In fact, you don't even have to keep a reference to the Thread object that you created. You can simply write this as one line: new Thread(new ThreadStart(obj.MyMethod)).Start();

        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