winzip icon

Simple Multi Thread Example

Email
Submitted on: 1/2/2015 8:46:00 AM
By: Jose Fuentes VB MVP (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: VB.NET
Views: 1221
 
     I've had a few people come to me with how to do multi treading. I've looked around PSC and there are plenty of projects that have multi-threading but none solely for multi-threading. So I did up a simple multi-threading console application that passes data back to the parent thread via events. This is a very simple example and is designed to show how multi-threading can be used. The key to understanding what you would use multi-threading for is to keep one simple thing in mind. All UI (user interfaces) elements must be in the parent thread. You can not have anything that interacts direct with the UI in a seperate thread. For example if you are running a long business process and get an exception, then use a message box to show that exception then nothing will ever be shown to the user. It's in a background thread so the user never see's it. It can also lock the application up since the messagebox is waiting for the user to click ok. What you would do in such an example would be to pass the error message back to the parent thread and let the parent thread display the error message. This is also a good example to show how you could update a progress bar on the parent thread with the process of the thread (like how far along the process has gotten in getting or doing something). Hope this helps. Sometimes you just need to break something down to bare basics to get a good understanding of it. Though this is only one example of how to work with threads, there are many other ways.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 18 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.