By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

Passing parameter to thread

P: n/a
Hi, All
I am wandering in 1.1 version of C#, how can I pass parameters to
thread?
In article http://www.yoda.arachsys.com/csharp/threadstart.html, it
provides a way to pass one parameter. It looks like not possible to pass
more than one.

Anybody has a solution?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Hardy Wang" <ha*******@hotmail.com> skrev i en meddelelse
news:uV**************@TK2MSFTNGP10.phx.gbl...
Hi, All
I am wandering in 1.1 version of C#, how can I pass parameters to
thread?
In article http://www.yoda.arachsys.com/csharp/threadstart.html, it
provides a way to pass one parameter. It looks like not possible to pass
more than one.

Anybody has a solution?


The solution on the website shows an example with one parameter. The
UrlFetcher class has a "parameter" called url. You could easily add other
parameters/properties to this class, set them appropriately, and then start
the thread which uses them (a function called Fetch).
Nov 17 '05 #2

P: n/a
i just relized i had that commented out (sorry notepad has no colors) but im
sure this code worked if you can follow
private void mailit()
{

smtp mail = new smtp();
mail.to = txtTo.Text;
mail.from = txtFrom.Text;
mail.name = txtName.Text;
mail.subj = txtSub.Text;
mail.body = txtBody.Text;
mail.label9 = label9;
//mail.pool = listBox2;
mail.srv = ssrv;
mail.inx = ind.ToString();

mail.listBox1 = listBox1;
mail.amount = (Convert.ToInt32(txtAmt.Text)/threads);

if (ind != threads)
{

ind++;
if (started == 0)
{
ThreadStart startz = new ThreadStart(mailit);
worker[ind] = new Thread(startz);
}

worker[ind].Start();

if (ind == (threads-1))
{
}

}

mail.Mail();
}

private void button1_Click(object sender, System.EventArgs e)
{
//to do
//amount sent fix
//add waitOne to the socket class not in the mail class, use timeout
paramater etc
//make this project for exfilter command line
string server;
threads = Convert.ToInt32(txtThreads.Text);
smtp mail2 = new smtp();
if (ind > 0)
{ started=1;
server =
txtTo.Text.Substring(txtTo.Text.IndexOf("@")+1,(tx tTo.Text.Length-txtTo.Text.IndexOf("@")-1));
ssrv=mail2.MXLookup(server);
listBox1.Items.Add("00 - Started at "+System.DateTime.Now);
ind=0;
ind++;
worker[ind].Start();
}
else
{

tp.SetMaxThreads(100,5000);

ThreadStart startz = new ThreadStart(mailit);

server =
txtTo.Text.Substring(txtTo.Text.IndexOf("@")+1,(tx tTo.Text.Length-txtTo.Text.IndexOf("@")-1));
ssrv=mail2.MXLookup(server);
listBox1.Items.Add("00 - Started at "+System.DateTime.Now);

ind++;
worker[ind] = new Thread(startz);
worker[ind].Start();

}

"Hardy Wang" wrote:
Hi, All
I am wandering in 1.1 version of C#, how can I pass parameters to
thread?
In article http://www.yoda.arachsys.com/csharp/threadstart.html, it
provides a way to pass one parameter. It looks like not possible to pass
more than one.

Anybody has a solution?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Nov 17 '05 #3

P: n/a
just create an object and pass it to the thread. Here is code i did for a
email blaster
mail[i] = new smtp();
mail[i].to = txtTo.Text;
mail[i].from = txtFrom.Text;
mail[i].name = txtName.Text;
mail[i].subj = txtSub.Text;
mail[i].body = txtBody.Text;
mail[i].ssrv = ssrv;
mail[i].listBox1 = listBox1;
ThreadPool.QueueUserWorkItem(new WaitCallback(mail[i].Mail), i);
}*/
my code was using an array of object[i] so ignore that =)

you can use that to control what thread number or index your on etc..

Michael Evanchik
not a MVP
www.michaelevanchik.com

"Hardy Wang" wrote:
Hi, All
I am wandering in 1.1 version of C#, how can I pass parameters to
thread?
In article http://www.yoda.arachsys.com/csharp/threadstart.html, it
provides a way to pass one parameter. It looks like not possible to pass
more than one.

Anybody has a solution?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.