473,466 Members | 1,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing parameter to thread

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
3 12921

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Job Lot | last post by:
How can I pass parameters to a procedure which is called in thread? '! Spin off a new thread. myThread = New Thread(New ThreadStart(AddressOf GetRawFigures)) myThread.IsBackground = True...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
2
by: cmrchs | last post by:
Hi, Is there a way to pass a parameter to a thread ? Creating a thread is done using a ThreadStart-delegate object example : Thread thread1 = new Thread(new ThreadStart(MyFunction)) ...
2
by: Carlos | last post by:
Hi all, I am familiar with passing parameters to a thread function using C++, but I needt to learn it using C#. Can someone shed some light on how to do this? Code snippets will be great to show...
3
by: Sam Learner | last post by:
Hello everyone, I am developping an application, I create a thread for the application because it is about to download a large file, and wanted it to do it inside of a thread... Now, the function...
3
by: brian_harris | last post by:
I am tring to start a thread where I am passing info into thread. According to MS documentation I must do this by creating a class for that thread. I have done this but am getting a compiler...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
2
by: JackC | last post by:
Hi, I create my threads like this: for(int j = 0; j < 5; j++) { boost::thread *thr = new boost::thread(worker_func); threads.add_thread(thr); }
8
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.