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

Passing parameters to a thread

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: 28
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(string progress)
{

label1.label=progress;

}


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

P: 28
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 discussion thread is closed

Replies have been disabled for this discussion.