Search | Contact | Link To Us  


      VB .NET      

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement

visual basic, threaded applications in vb.net, .net, multi threading in .net, .net streams, .net files,.net deployment, deploying .net applications, .net languages, microsoft .net, .net assemblies, .net controls, microsoft languages, programming, progrmmaing .net, programming vb.net, compiling assemblies, compile .net applications,programming visual basic.net








     Home> Multithreading> Thread Priorities


Multithreading

Suspending a Thread

Threads can be suspended. Suspending a thread stops it temporarily. Working with the example in the previous section, add a new button Button2 to the main form. When this button is clicked the thread is suspended. The code for that looks like this:

Private Sub Button2_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button2.Click
Thread1.Suspend()
End Sub

Resuming a Thread

Threads can be resumed after they are suspended. With the example above, add a new button Button3 to the main form. When this button is clicked the thread is resumed from suspension. The code for that looks like this:

Private Sub Button3_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button3.Click
Thread1.Resume()
End Sub

Making a Thread Sleep

Threads can be made to sleep which means that they can be suspended over a specific period of time. Sleeping a thread is achieved by passing the time (in milliseconds,1/1000 of a second) to the thread's sleep method. With the example above, add a new button Button4 to the main form. When this button is clicked the thread is stopped. The code for that looks like this:

 
Private Sub Button4_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button4.Click
Thread1.Sleep(100/1000)
End Sub

Stopping a Thread

Threads can be stopped with it's abort method. With the example above, add a new button Button5 to the main form. When this button is clicked the thread is stopped. The code for that looks like this:

Private Sub Button5_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button5.Click
Thread1.Abort()
End Sub

Thread Priorities

Threads can also be assigned priority for execution. Thread priority can be set by the thread's Priority property and assigning a value from predefined Thread Priority enumeration.

Values for Thread Priority:

Above Normal -> Gives thread higher priority
Below Normal ->Gives thread lower priority
Normal -> Gives thread normal priority
Lowest -> Gives thread lowest priority
Highest -> Gives thread highest priority

Working with the above example, add a new button Button6 to the main form. When this button is clicked the thread is assigned Highest priority .The code for that looks like this:

Private Sub Button6_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button6.Click
Thread1.Priority=System.Threading.ThreadPriority.Highest
'setting Highest priority for the thread
End Sub

For more information on Threads please refer to MSDN.

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.