473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameters to a thread

We are building a threaded application which reacts to an event and starts
the required processing on a new thread.

However, we are finding it difficult finding a way of getting the function
to run using its own data. I've looked at SetData and GetData but these seem
only to be available once the thread is running.

The ThreadStart delegate won't allow me to use a function with parameters..
so I can see now way that a parent thread can pass a parameter to a child
thread (a file name in this instance) in a thread safe way.

Does anyone out there have any ideas as to how this can be done? It seems to
me that the SetData and GetData have limited usefulness if you cannot pass
thread specific data to the thread.

Thanks



Nov 13 '05 #1
2 14021
shanthsp2002
28 New Member
I am developing installer in which i am using custom installer class, my client want me to show a different window while installation to show progress of installation insted of the regular progressbar, so i have to use thread here

i have created new form and in form1.cs i have created a method like

privare void UpdateLabel(str ing progress)
{

label1.label=pr ogress;

}


now i have to call this in my custom installer class and there i will pass
parameters to this function


Thread th=new thread(new threadStart(Pr. UpdateLabel))
th.start();

bu how to pass parameter to this method is a big qustion for me

if u got any idea plzz inform me too

thank u



We are building a threaded application which reacts to an event and starts
the required processing on a new thread.

However, we are finding it difficult finding a way of getting the function
to run using its own data. I've looked at SetData and GetData but these seem
only to be available once the thread is running.

The ThreadStart delegate won't allow me to use a function with parameters..
so I can see now way that a parent thread can pass a parameter to a child
thread (a file name in this instance) in a thread safe way.

Does anyone out there have any ideas as to how this can be done? It seems to
me that the SetData and GetData have limited usefulness if you cannot pass
thread specific data to the thread.

Thanks
Jun 16 '06 #2
shanthsp2002
28 New Member
Hi here is some code u can look at , i dont know werther i will work, but it looks to be working try it, all the best


public class UrlFetcher
{
string url

public UrlFetcher (string url)
{
this.url = url;
}

public void Fetch()
{
// use url here
}
}

[... in a different class ...]

UrlFetcher fetcher = new UrlFetcher (myUrl);
new Thread (new ThreadStart (fetcher.Fetch) ).Start();
Jun 16 '06 #3

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

Similar topics

3
14952
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
18407
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
2869
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;
3
8053
by: rollasoc | last post by:
Hi, Having a slight problem with how to pass parameters to functions between threads. I have a form with a progress bar and a description label on it. It has a public function IncrementProgressBar() that just calls performstep on the progress bar.
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
1824
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...
9
1754
by: Raith | last post by:
Ok I'm still very new to C# and I've been searching around and getting myself all confused so gave up and am posting here. Vastly simplified but I have a form with some tick boxes on it, clicking on ok populates an array with the values selected and runs a process passing the array, a bit like below... public void process(string valuesArray) { // Do stuff that takes a while here.
14
6890
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a datagridview on the form. I am using the following code to spawn the worker thread... Thread WorkerThread = new Thread(new ThreadStart(WT_MyFunction)); WorkerThread.IsBackground = true; WorkerThread.Start(); The problem I am having is...I cannot seem...
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
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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
9950
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
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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
5381
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...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.