I need to call a couple of methods asynchronously with different priorities.
My first idea was to use the ThreadPool and change the priority of the Thread like this:
static void Run() { ThreadPool.QueueUserWorkItem(new WaitCallback(SomeMethod)); } static void SomeMethod(object o) { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; // is this ok? // do some work here }
Does that work or what do you recommend?
According to http://msdn.microsoft.com/en-us/library/0ka9477y.aspx, it won’t work if you are targeting 2.0, it alludes to there being some differences in 3.5 but doesn’t specifically mention priority:
You’ll likely need to come up with your own implementation, and handle creation of Threads directly.
Question: What are you trying to achieve do you have a set of tasks to be processed and you want high priority tasks to happen first, and lower ones to happen later; or do you actually want Threads of differing priority?