473,769 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ 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 12941

"Hardy Wang" <ha*******@hotm ail.com> skrev i en meddelelse
news:uV******** ******@TK2MSFTN GP10.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.ToInt3 2(txtAmt.Text)/threads);

if (ind != threads)
{

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

worker[ind].Start();

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

}

mail.Mail();
}

private void button1_Click(o bject sender, System.EventArg s 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.Tex t);
smtp mail2 = new smtp();
if (ind > 0)
{ started=1;
server =
txtTo.Text.Subs tring(txtTo.Tex t.IndexOf("@")+ 1,(txtTo.Text.L ength-txtTo.Text.Inde xOf("@")-1));
ssrv=mail2.MXLo okup(server);
listBox1.Items. Add("00 - Started at "+System.DateTi me.Now);
ind=0;
ind++;
worker[ind].Start();
}
else
{

tp.SetMaxThread s(100,5000);

ThreadStart startz = new ThreadStart(mai lit);

server =
txtTo.Text.Subs tring(txtTo.Tex t.IndexOf("@")+ 1,(txtTo.Text.L ength-txtTo.Text.Inde xOf("@")-1));
ssrv=mail2.MXLo okup(server);
listBox1.Items. Add("00 - Started at "+System.DateTi me.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.Queu eUserWorkItem(n ew WaitCallback(ma il[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
18406
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 myThread.Start() Procedure GetRawFigures takes an argument as follows: Private Sub GetRawFigures(ByVal figures As Integer())
7
2868
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 parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
6
2800
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 in C# and we're using remoting for client to server communication.
2
3472
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)) Unfortunately, it doesn't allow me to pass arguments to MyFunction since the definition of the ThreadStart is :
2
2189
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 me. Thanks in advance, Carlos
3
2031
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 I need the thread to call has a parameter... How do I call a function with the addressof(..) with a parameter value? for example: public function processData(byval data as arraylist) as boolean.... ....
3
1823
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 error. The error is: c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(104): error C2475: 'ThreadWithState::readerThread' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name...
6
6871
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 ThreadStart(open)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
2
3736
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
9433
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 Summation(LPVOID Param) {
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.