JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Setting Thread Priority

You can set the priority of threads with the Priority property. The ThreadPriority enumeration lists the possible values (a thread with higher priority gets more time than one with lower priority):

  • AboveNormal— Gives a thread higher priority.

  • BelowNormal— Gives a thread lower priority.

  • Highest— Gives a thread highest priority.

  • Lowest— Gives a thread lowest priority.

  • Normal— Gives a thread average priority.

Using the Priority property, you have some control over how much time a thread gets, compared to others. For example, here's how you give a thread the highest priority:

NewThread.Priority = System.Threading.ThreadPriority.Highest

For example, we set the priority of a thread in the Threading example discussed in the In Depth section of this chapter. When the user clicks the "Set Low Priority" button in that example, the new thread is assigned "below normal" priority. Here's how that looks in code (you can see this at work in Figure 24.10):

    Private Sub Button4_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button4.Click
        Thread1.Priority = System.Threading.ThreadPriority.BelowNormal
    End Sub

For more on how this example works, take a look at the discussion in the In Depth section of this chapter.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor