Another Threading Question
-
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
-
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
-
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
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();