473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
IncrementProgre ssBar() 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.In crementProgress Bar);

this.BeginInvok e(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.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(m_ProgressBar .UpdateTitle, args);

but the first line doesn't compile.

Rollasoc




Nov 15 '05 #1
3 8046
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.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(m_ProgressBar .UpdateDescript ion, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmai l.com> wrote in message
news:ud******** ******@TK2MSFTN GP10.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
IncrementProgre ssBar() 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.In crementProgress Bar);

this.BeginInvok e(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.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(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 "someMessag e" 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.someMessag e = "Some Message";
new Thread(new ThreadStart(thi s.MyThreadFunct ion())).Start() ;

}

public void MyThreadFunctio n()
{
DoSomething(thi s.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

MethodInvoke r mi = new MethodInvoker(m _ProgressBar.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(m_ProgressBar .UpdateDescript ion, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmai l.com> wrote in message
news:ud******* *******@TK2MSFT NGP10.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
IncrementProgre ssBar() 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.In crementProgress Bar);

this.BeginInvok e(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.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(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**********@o nline.microsoft .com> wrote in message
news:Am******** ******@cpmsftng xa06.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 "someMessag e" 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.someMessag e = "Some Message";
new Thread(new ThreadStart(thi s.MyThreadFunct ion())).Start() ;

}

public void MyThreadFunctio n()
{
DoSomething(thi s.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

MethodInvoke r mi = new MethodInvoker(m _ProgressBar.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(m_ProgressBar .UpdateDescript ion, args);

but the first line doesn't compile.
"rollasoc" <ho*****@hotmai l.com> wrote in message
news:ud******* *******@TK2MSFT NGP10.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
IncrementProgre ssBar() 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.In crementProgress Bar);
this.BeginInvok e(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.Up dateDescription );

object[] args = {m_txtUpdateDes cription.Text};

this.BeginInvok e(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
17348
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 (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
7
49570
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. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
1
4378
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 you also pass along a username or password that sits on a form? Thank you. Kevin
2
2183
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
0
1548
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 "codebehind" page. Function declaration: Sub MyFunction(ByVal sender As Object, ByVal e As System.EventArgs)
4
2988
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 pass it to the Db and retrieveing data from a stored procedure, but I can't get the hang of parameters. I have a method where I can get the parameters passed to the sp but it doesn't want to return any results. Here's a copy of my code:
4
3888
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 worked so far. Thanks for any help!
2
2019
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 as was the case in the previous version of VB e.g. VB .Net 2003. Here's the procedure in the web service: Public Sub Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount As Double) Dim exchangeRate As Double exchangeRate = 10 / 6
18
2859
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 write an ordinary differential equation class that would solve a general equation in the form: dx/dt = f(x,t). The ode class shouldn't know anything about f, except how to call it.
0
8315
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
8829
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...
0
8734
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
8508
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
8608
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
7341
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...
0
5633
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
4164
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...
2
1627
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.