I have reserched and I realised that actually there is no way to make preemptive scheduling mechanisms in C#, am I right?
So, I have to simulate it by using cooperative scheduling mechanisms.
Actually I have to make API, so my idea is to use some Token, and if that Token is set, then I have to stop currently running Task, run Task with bigger priority, and then continue stopped Task..
So, here is my question. I can not find a good way to stop Task, and continue it later, so is there any way to do that. I have one idea to do nothing in while loop until that token is set, so it will seem like I stopped that Task, and continue later (this is just simulation).. But I hope that there is some better way..
Also I have find EventWaitHandle Class, but I am not sure if I can manage with individual Threads or Tasks.
Actually, I have to make my own Scheduler (of course not something really good, just simulation).. So I have to give him Tasks with priorities, and Scheduler have to schedule that, but if in some moment I add one more Task, and if it has bigger priority, I have to stop current Task, run Task with bigger priority, and when this Task finish, I have to continue stopped Task.. So I have to know if there any good way to suspend Task (but without using Suspend function, because it can make deadlock, and not good to use)...