I seem to fail to create a foreground task. my main thread is supppose to call another thread and then exit. the other thread suppose to run forever
void MainThreadMain()
{
task_main = Task.Factory.StartNew(() => OtherThread()) ;
return;
}
void OtherThread()
{
while(true)
{
TellChuckNorrisJoke();
}
}
how can I ensure task_main will continue running even that Main Thread is dead? I assumed il do:
task_main.IsBackgorund = false;
but no such option :\ I can make my main thread to wait a signal from my other thread that it passed to Foreground mode. but thats plain silly.
The obvious question is: why don't you run your work on the main thread?
Assuming this is not an option, you should use a Thread
not a Task
. Then you can set:
Thread.IsBackground = false;
This will prevent your application from terminating while the worker thread is running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With