The constrctor for a Thread class accepts a ThreadStart delegate. Whatever method you pass to Thread constructor must match the ThreadStart delegate. The ThreadStart delegate has no parameters, and your ClientProcess method does; you need to remove the param from that method. If you need to pass values into your ThreadStart delegate you can do something like this:PHP Code:using System;
using System.Threading;
namespace Tester
{
public class MainApp
{
public static void Main( string[] args )
{
Worker worker = new Worker("Chris");
Console.WriteLine("Before: Worker valid? {0}", worker.Valid);
Thread t = new Thread(new ThreadStart(worker.DoSomething));
t.Start();
while(t.IsAlive && !worker.Valid)
{
Thread.Sleep(200);
}
Console.WriteLine("After: Worker valid? {0}", worker.Valid);
Console.WriteLine("Done...");
Console.ReadLine();
}
}
public class Worker
{
private string _name = "";
private bool _valid = false;
public bool Valid
{
get
{
return _valid;
}
set
{
_valid = value;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public Worker(string name)
{
this._name = name;
}
public void DoSomething()
{
this._valid = true;
Console.WriteLine("Hello {0} from the ThreadStart delegate", this.Name);
}
}
}




Reply With Quote