473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need help using system.Threading...

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

May 8 '07 #1
4 7362
that won't work...
use should use ParameterizedThreadStart (only in FW 2.0)
http://msdn2.microsoft.com/en-us/lib...readstart.aspx

you have to create delegate which accept single parameter which of the
object type,
and pass the value to the thread.Start method.

May 8 '07 #2
See
http://www.yoda.arachsys.com/csharp/...rameters.shtml

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

May 8 '07 #3
Yep perfect! thanks for your quick response and help :-))

regards,
Paul

"TS25" <xx*@xxx.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
that won't work...
use should use ParameterizedThreadStart (only in FW 2.0)
http://msdn2.microsoft.com/en-us/lib...readstart.aspx

you have to create delegate which accept single parameter which of the
object type,
and pass the value to the thread.Start method.

May 8 '07 #4
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
May 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
1
by: Tom | last post by:
I've googled, and read, and stripped out code, and rewritten code, and still can't get a System.Threading.Timer to work. (I hereby publicly admit that I'm a failure here...) Could someone please...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
2
by: Stig Hausberg | last post by:
Hi folks! I'm currently working in a prototype project as we are moving into dotnet and I've have stumbled upon an issue someone hopefully can help me with. The system we are building needs to...
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
0
by: Bruce | last post by:
Hi I have a question on using System.Threading.Timer. I understand that in order for the timer to work, I need to store a reference to the timer so that it does not get garbage collected. In my...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
2
by: PimpDaddy | last post by:
Here is the source code of my C++/ME app. When I run it I can use "Windows Task Manager" to see that thread HANDLEs are leaking. #include "stdafx.h" #include <omp.h> public __gc class...
2
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've two questions regarding the System.Threading.Thread namespace. First, what is the point of having a ThreadStart parameter? For example... using System.Threading;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.