Passing parameters to Threads
Often when you start a thread, you want to give it some parameters - usually some data it has to process, a queue to wait on, etc. The ThreadStart delegate doesn't take any parameters, so the information has to be stored somewhere else if you are going to create a new thread yourself. Typically, this means creating a new instance of a class, and using that instance to store the information. Often the class itself can contain the delegate used for starting the thread. For example, we might have a program which needs to fetch the contents of various URLs, and wants to do it in the background. You could write code like this: public class UrlFetcher { string url ; public UrlFetcher ( string url) { this .url = url; } public void Fetch() { // use url here } } [... in a different class ...] UrlFetcher fetcher = new UrlFetcher (myUrl); new Thread ( new ThreadStart (fetcher.Fetch)).Start(); In some cases, you actually just wish to call a method in some class (possibly the current...