need help using system.Threading...

M

Milsnips

Hi there,

i've created a little test app where i send an email to myself and select a number from a combobox how many times to send it.

My sending function is called
void doMailSend()
{
//send the email here...
}

and it works fine with threading, however i want to pass an incrementing value to it to reference a datagrid row, so what i would like to do is the following:
void doMailSend(int rowPosition)
{
//send the email here...
}

for (int i = 0; i < emailcount.Value; i++)
{
Thread t = new Thread(new ThreadStart(doMailSend(i)));
t.Start();
}

and....

but the compiler throws me back an error at this line and i dont know what to do to solve it..:

No overload for 'doMailSend' matches delegate 'System.Threading.ThreadStart'


any help appreciated,

thanks,
Paul
 
M

Marc Gravell

For reference, if you have a more complex scenario, then you would
have to use some kind of state class to pass multiple parameters and
retreive feedback... unless you get the compiler to write all that
plumbing for you:

int count = someLocalCount;
Thread t = new Thread((ThreadStart) delegate {
// this inner brace executes on the new thread
doMailSend(count); // with lots more parameters
});

In either case, watch out for thread-affinity - you can't read UI
properties on the worker thread - but you can read them into local
variables on the UI thread which are then "captured" into the
anonymous method.
The thread affinity is why the above might be useful to pass in "to",
"cc", "subject", "from", ... etc

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top