Re: Threading - Is This Clever or Stupid?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: singleton application :)
    ... >> Florida Department Of Transportation ... >>> Ignacio Machin, ... >>> compilation of the differents methods. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading heavy .TXT file with StreamReader
    ... >> Ignacio Machin, ... >> Florida Department Of Transportation ... >>> I need a good performance way for reading so heavy .txt files. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: I need Just a Grid, Not DataGrid
    ... >> if web app, you have controls like the Repeater, which are easier to use. ... >> Ignacio Machin, ... >> Florida Department Of Transportation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Import data to db with c#
    ... DB1 ... >>> Ignacio Machin, ... >>> Florida Department Of Transportation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading Question
    ... Take a look at Jon Skeet's article in ... Ignacio Machin, ... Florida Department Of Transportation ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)