I just trying to pass some values but it’s throwing an error all the time. Can some one correct me what I am missing here?
Am getting error here
Thread t_PerthOut = new Thread(new ThreadStart(ReadCentralOutQueue("test"));
I want to pass this string value to ReadCentralOutQueue.
class Program
{
public void Main(string[] args)
{
Thread t_PerthOut = new Thread(new ThreadStart(ReadCentralOutQueue("test"));
t_PerthOut.Start();
}
public void ReadCentralOutQueue(string strQueueName)
{
System.Messaging.MessageQueue mq;
System.Messaging.Message mes;
string m;
while (true)
{
try
{
}
else
{
Console.WriteLine("Waiting for " + strQueueName + " Queue.....");
}
}
}
catch
{
m = "Exception Occured.";
Console.WriteLine(m);
}
finally
{
//Console.ReadLine();
}
}
}
}
This code:
tries to call
ReadCentralOutQueueand then create a delegate from the result. That isn’t going to work, because it’s a void method. Normally you’d use a method group to create a delegate, or an anonymous function such as a lambda expression. In this case a lambda expression will be easiest:You can’t just use
new Thread(ReadCentralOutQueue)as theReadCentralOutQueuedoesn’t match the signature for eitherThreadStartorParameterizedThreadStart.It’s important that you understand why you’re getting this error, as well as how to fix it.
EDIT: Just to prove it does work, here’s a short but complete program: