I have a question about using of Task.
I write the follow code:
static void Main(string[] args)
{
Task t = new Task(() => DoWork());
}
private static void DoWork()
{
//Do Something
}
DoWork is run on thread from ThreadPool.
for the example let assume the thread num is 3.
My Question: There is option that in middle of the func DoWork, because of context switch etc', the continuous of the function will be in thread that is not 3?
Thank!
My Question: There is option that in middle of the func DoWork, because of context switch etc', the continuous of the function will be in thread that is not 3?
No, context switch doesn't mean it goes to a different thread, just that processor core takes up a different thread / logic to process, this one still goes on the same thread. Most of the threads have same priority until and unless scheduled by CLR like GC or OS, which will have priority over other threads and freeze all other threads. Rest all have to keep on leaving processor core after some logical processing or I must say Processor core (Thread scheduling logic) keep scheduling other threads, thus not starving any of them. Please note at a given time, processor core can only schedule one thread / unit of work
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