473,408 Members | 2,405 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,408 software developers and data experts.

Threading Question. Passing parameters to a function.

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.
On my main form I create a thread which creates the progress bar form

Then using

MethodInvoker mi = new MethodInvoker(m_ProgressBar.IncrementProgressBar);

this.BeginInvoke(mi);

I can get this function called wherever is appropriate.

All is fine. But I want a function that takes a string as a parameter so I
can dynamically update the description.

Any idea how to do this? I've searched google and found nothing so far.

I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateTitle, args);

but the first line doesn't compile.

Rollasoc




Nov 15 '05 #1
3 8029
Sorry cut and pasted the wrong bit of code. (which obviously doesn't work)

It shoul have been
I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateDescription, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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.
On my main form I create a thread which creates the progress bar form

Then using

MethodInvoker mi = new MethodInvoker(m_ProgressBar.IncrementProgressBar);

this.BeginInvoke(mi);

I can get this function called wherever is appropriate.

All is fine. But I want a function that takes a string as a parameter so I can dynamically update the description.

Any idea how to do this? I've searched google and found nothing so far.

I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateTitle, args);

but the first line doesn't compile.

Rollasoc



Nov 15 '05 #2
I don't understand why you need to use MethodInvoke in order to call your
function (It seems you are trying a combination of threading and
reflection). You could use something like the next sample, where I am using
the member variable "someMessage" as a way of passing the string to the new
thread. Perhaps you will have to add some synchronization to the
someMessage variable.
public class MyClass
{
private string someMessage;

public void DoSomething()
{
//....
this.someMessage = "Some Message";
new Thread(new ThreadStart(this.MyThreadFunction())).Start();

}

public void MyThreadFunction()
{
DoSomething(this.someMessage);
}
}

You could also consider sending some notifications to update the
slider/message.

Sorry cut and pasted the wrong bit of code. (which obviously doesn't work)

It shoul have been
I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateDescription, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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.
On my main form I create a thread which creates the progress bar form

Then using

MethodInvoker mi = new MethodInvoker(m_ProgressBar.IncrementProgressBar);

this.BeginInvoke(mi);

I can get this function called wherever is appropriate.

All is fine. But I want a function that takes a string as a parameter so

I
can dynamically update the description.

Any idea how to do this? I've searched google and found nothing so far.

I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateTitle, args);

but the first line doesn't compile.

Rollasoc


Adrian Vinca [MSFT], Developer Division
--------------------------------------------------------------------
This reply is provided "AS IS", without warranty (express or implied).

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #3
Your right. There was no need really. I was going on what few articles I
could find. I have since found some very useful articles on the microsoft
site.

Completely sorted the whole thing with delegates and using BeginInvoke on
them.

Works great now.

Rollasoc
"Adrian Vinca [MSFT]" <ad**********@online.microsoft.com> wrote in message
news:Am**************@cpmsftngxa06.phx.gbl...
I don't understand why you need to use MethodInvoke in order to call your
function (It seems you are trying a combination of threading and
reflection). You could use something like the next sample, where I am using the member variable "someMessage" as a way of passing the string to the new thread. Perhaps you will have to add some synchronization to the
someMessage variable.
public class MyClass
{
private string someMessage;

public void DoSomething()
{
//....
this.someMessage = "Some Message";
new Thread(new ThreadStart(this.MyThreadFunction())).Start();

}

public void MyThreadFunction()
{
DoSomething(this.someMessage);
}
}

You could also consider sending some notifications to update the
slider/message.

Sorry cut and pasted the wrong bit of code. (which obviously doesn't work)

It shoul have been
I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateDescription, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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.
On my main form I create a thread which creates the progress bar form

Then using

MethodInvoker mi = new
MethodInvoker(m_ProgressBar.IncrementProgressBar);
this.BeginInvoke(mi);

I can get this function called wherever is appropriate.

All is fine. But I want a function that takes a string as a parameter soI
can dynamically update the description.

Any idea how to do this? I've searched google and found nothing so

far.
I've tried

MethodInvoker mi = new MethodInvoker(m_ProgressBar.UpdateDescription);

object[] args = {m_txtUpdateDescription.Text};

this.BeginInvoke(m_ProgressBar.UpdateTitle, args);

but the first line doesn't compile.

Rollasoc


Adrian Vinca [MSFT], Developer Division
--------------------------------------------------------------------
This reply is provided "AS IS", without warranty (express or implied).

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #4

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

Similar topics

2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
1
by: No Spam | last post by:
Dear Access 2003 Users, Is there any way to launch Terminal Server from Access and pass along the user name that is in a text box? I believe mstsc.exe can be passed an IP address (/v), but can...
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...
0
by: Paul Allan | last post by:
I am new to ASP.net (intermediate ASP developer). I am developing a ASP.net web application and I am having some difficulty calling and passing parameters to a function that is declared in my...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
4
by: ingoweiss | last post by:
Hi, I am having trouble passing parameters of a Javascript subclass constructor through to it's superclass constructor. I am trying all sorts of things, including the below, but nothing...
2
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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,...

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.