views:

75

answers:

2

what is multithreading and how do i do it in vb.net?

+1  A: 

Here's a tutorial to get you started.

As for what it is, this is from Wikipedia:

In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.

Jon B
+1  A: 

Multi-threading is the concept of making a program do multiple things concurrently. A common use case is to do some intense processing in the background, while keeping the UI thread alive and responding to messages, or to split up a large problem and parallellize the finding of a solution across multiple CPUs (or cores).

You can add multithreading to your .NET application by working with the Thread class.

Note that making multi-threaded stuff work usually requires careful synchronization handling, using concepts like mutexes and semaphores. Without this, you can run into various issues that can be insanely difficult to locate, because they do not appear in a deterministic fashion, since it's now up to the OS to schedule processing time to each thread. A saying I've heard several times is that threads are evil. What that means is that they always run when you don't want them to run, inevitably running into that one place you aren't doing proper synchronization - but when you then try to find the error, you can't duplicate it with the debugger running, because now, the OS schedules the threads slightly differently, avoiding the bug.

Michael Madsen