Question

I have an action,

var act = new Action(() =>
{
   while (true)
   {
     //Some Codes!
   }
 });
 act.BeginInvoke(null, null);

How can I increase the priority of the thread that runs this action? I know how can I do it in simple thread.

Thread.CurrentThread.Priority = ThreadPriority.Lowest;

But how about an action's priority?

Was it helpful?

Solution

BeginInvoke will queue your task to the ThreadPool. You have no control over the dispatching of the standard .NET ThreadPool. You can only control the thread once your code actually executes.

WARNING: Changing priority of a ThreadPool Thread is considered dangerous. Further Reading: .NET: Why not change the priority of a ThreadPool (or Task) thread?

If you can explain what you're trying to achieve, perhaps you can get a better solution?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top