Hi all,
I have a method that needs to execute a lot of times. I want to drop my
code in there but also the method expects two paramaters for everything
to work as expected. No I am faced with the following issue.
I use the System.Threading.ThreadPool class to queue the executions. My
current code looks like this:
foreach (string f in FileList)
{
bool u = true;
ThreadPool.QueueUserWorkItem(new
WaitCallback(CreateK2_Excist), f );
I want to be able to pass in u and f but I can only get the WaitCallback to accept 1
paramater.
How would it be possible to pass in two paramaters too my method??
Thanks in advance!
{SpGh}
Loading
Raaj KumarPosted Feb 26, 2010, 4:39 AM
Just put the parameters inside a Dictionary and pass it as a parameter. Like this,
Dictionary
params.add("U",u);
params.add("f",f);
ThreadPool.QueueUserWorkItem(new WaitCallback(CreateK2_Excist), params );
void CreateK2_Excist(object state)
{
//Type cast state to dictionary and use it.
}
Regards,
raaj