473,385 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 14008
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
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
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) {...
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...
3
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...
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: 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...
9
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,...
14
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.