Re: Threading - Is This Clever or Stupid?
- From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
- Date: Mon, 1 Aug 2005 10:26:40 -0400
Hi,
Take a look at http://www.yoda.arachsys.com/csharp/threads/parameters.shtml
There jon explain how to pass parameters to threads.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"pagates" <pagates@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:53D005CB-F467-43A4-ADDF-A76C14CD81EE@xxxxxxxxxxxxxxxx
> Hi All,
>
> Just a general threading question. Would it be considered good
> programming
> practice, or a bad idea, or whatever, to create a thread with a special
> name
> in order to "pass parameters" to the thread.
>
> In other words, something like this simple example:
>
> btnRunThreads_Click(object sender, EventArgs e)
> {
> for (int i = 1; i <= 10; i++)
> {
> ThreadStart workerStart = new ThreadStart(StartMethod);
> Thread workerThread = new Thread(workerStart);
> workerThread.Name = "Worker_" + i.ToString();
> workerThread.Start();
> }
> }
>
> void StartMethod()
> {
> Thread thisThread = Thread.CurrentThread;
> string threadName = thisThread.Name;
> string Task = threadName.Substring(threadName.IndexOf("_") + 1);
>
> switch (Task)
> {
> case "1":
> DoTaskOne();
> break;
>
> case "2":
> DoTaskTwo();
> break;
>
> // More cases, etc.
>
> case "10":
> DoTaskTen();
> break;
>
> default:
> break;
> }
> }
>
> More "parameters" could be added by continuing to use a separator
> character
> (probably an underscore, since it needs to be a valid thread name), and
> using
> (for instance) the string.split command to enumerate them.
>
> What say you, oh wise ones?
>
> Thanks,
> pagates
.
- References:
- Threading - Is This Clever or Stupid?
- From: pagates
- Threading - Is This Clever or Stupid?
- Prev by Date: Re: Instantiation of generics
- Next by Date: Re: C# ASP.Net interop with MsWord
- Previous by thread: Re: Threading - Is This Clever or Stupid?
- Next by thread: Access and Crystal Reports
- Index(es):
Relevant Pages
|