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

Calling a method with params on a form on a different thread, plea

Hi! I need to call a method with some parameters
on a form which was created on a different thread.

Here's how I create the form:
// Main Thread:
ThreadStart entryPoint = new ThreadStart(ShowSplashForm);
Thread splashFormThread = new Thread(entryPoint);
splashFormThread.Name = "Splash form thread";
splashFormThread.Start();

...................
public static frmSplash m_SplashForm;
public static void ShowSplashForm()
{
m_SplashForm = new frmSplash();
m_SplashForm.ShowDialog();
}

I can see that the form does get created on a new thread called "Splash form
thread"

Now the problem:
The frmSplash form has a public method called
UpdateCaption(string newCaption)

How do I call it from the main thread that created this form ?
is it possible ? Any ideas/examples are highly appreciated.
Nov 16 '05 #1
1 1310
Mike,

In the idea of a good design, I must tell you that windows forms are not
thread safe out of the box.

It is certainly possible to do so though, but the right way to do it would
be to use ContextSwitching using the invoke function. You'd need to create a
delegate to match the function signature to acheive this.

You could try going to www.gotdotnet.com under user samples and search for
"Splash Screen" for appropriate samples.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hi! I need to call a method with some parameters
on a form which was created on a different thread.

Here's how I create the form:
// Main Thread:
ThreadStart entryPoint = new ThreadStart(ShowSplashForm);
Thread splashFormThread = new Thread(entryPoint);
splashFormThread.Name = "Splash form thread";
splashFormThread.Start();

..................
public static frmSplash m_SplashForm;
public static void ShowSplashForm()
{
m_SplashForm = new frmSplash();
m_SplashForm.ShowDialog();
}

I can see that the form does get created on a new thread called "Splash form thread"

Now the problem:
The frmSplash form has a public method called
UpdateCaption(string newCaption)

How do I call it from the main thread that created this form ?
is it possible ? Any ideas/examples are highly appreciated.

Nov 16 '05 #2

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

Similar topics

3
by: Cindy Liu | last post by:
Hi Everyone, I created C# COM+ component. It has two overloaded methods - the method names are same and their signatures are different, one takes two parameters and another takes four. I coded...
2
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
4
by: MicroMoth | last post by:
Hi, I'm trying to write a update method, in which when the user clicks the update button the update method is passed 10 form fields. Then a update SQL is run to update the database. My question...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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...
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: 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...
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...

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.