ThreadStart

  • Thread starter Thread starter Maxime
  • Start date Start date
M

Maxime

Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter))); // Not Ok why? another way maybe ?

Max
 
Maxime said:
Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter))); //
Not Ok why? another way maybe ?

Max

Max,

You can't pass parameter info, to pass data between the threads have a
look at the example:

http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconcreatingthreads.asp

in the section "Passing Data To Threads"

basically the sample is:

[C#]
using System;
using System.Threading;

// The ThreadWithState class contains the information needed for
// a task, and the method that executes the task.
//
public class ThreadWithState {
// State information used in the task.
private string boilerplate;
private int value;

// The constructor obtains the state information.
public ThreadWithState(string text, int number) {
boilerplate = text;
value = number;
}

// The thread procedure performs the task, such as formatting
// and printing a document.
public void ThreadProc() {
Console.WriteLine(boilerplate, value);
}
}

// Entry point for the example.
//
public class Example {
public static void Main() {
// Supply the state information required by the task.
ThreadWithState tws =
new ThreadWithState("This report displays the number
{0}.", 42);
// Create a thread to execute the task, and then
// start the thread.
Thread t = new Thread(new ThreadStart(tws.ThreadProc));
t.Start();
Console.WriteLine("Main thread does some work, then waits.");
t.Join();
Console.WriteLine("Independent task has completed; main thread
ends.");
}
}



ed
 
Back
Top