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

Accessesing GUI from different thread

Whats the best way to access .net GUI classes from a spawned thread? Is
this even advisable, or is it a sign that the design is wrong?

Any input, links, etc., would be helpful. Thanks!

Steve
Nov 17 '05 #1
3 891
Steve,
Whats the best way to access .net GUI classes from a spawned thread? Is
this even advisable, or is it a sign that the design is wrong?


It is certainly possible, and certainly necessary at times. It's not
necessarily a wrong thing, though in some cases there might be alternatives.

That said, you do have to take a few things into account, and make sure you
marshal the GUI access back to the main thread (so that you never touch the
gui controls from secondary threads), but, fortunately, the .NET framework
provides a mechanism for this.

Here's a good article on the topic (it's in C#, but the principles are the
same):
http://www.code-magazine.com/article...0403071&page=1
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Nov 17 '05 #2
Steve N. wrote:
Whats the best way to access .net GUI classes from a spawned thread?
Is this even advisable, or is it a sign that the design is wrong?


The design is not wrong, but you jmust be careful to make your GUI API
thread-safe : each public function of your GUI objects that may be called on
different threads should begin by something like this (in C# for ease of
syntax, but you've got the idea) :

delegate void DoSomethingDelegate(params...) ///DoSomethingDelegate matches
DoSomething'signature
void DoSomething(params....)
{
if (InvokeRequired)
{
BeginInvoke (new DoSomethingDelegate(DoSomething, new object[]
{params...}));
return;
}

//normal GUI stuff
}

Arnaud
MVP - VC
Nov 17 '05 #3
Tomas Restrepo (MVP) wrote:
That said, you do have to take a few things into account, and make sure you
marshal the GUI access back to the main thread (so that you never touch the
gui controls from secondary threads), but, fortunately, the .NET framework
provides a mechanism for this.

Here's a good article on the topic (it's in C#, but the principles are the
same):
http://www.code-magazine.com/article...0403071&page=1


Yes, I got it working, thank you.
Nov 17 '05 #4

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

Similar topics

2
by: Ben Childs | last post by:
Hi, I am writing an application in C# (VS.NET 2002) that runs performance intensive analyses on data sets. In order to keep the UI responsive I have created a seperate thread to do the analysis....
3
by: asanford | last post by:
I want to create an ASP.NET web application that receives a form POST message, inspects the data, and reroutes the request to one of many different servers. I wrote an IHttpModule which...
3
by: DS | last post by:
I try to generate a excel workbook using Excel object in ASP.NET program. When I implement the Excel workbook generation with out a thread it works fine. When I wrap all the excel generation...
4
by: Charles Law | last post by:
Suppose a worker thread needs to signal to the main thread that an event has occurred. Ordinarily, any event raised by the worker thread will be on its own thread. How can the worker thread...
10
by: David | last post by:
I am trying to get this straight in my head so I can implement. I wrote a small utility some time ago in c# that utilized a handful of threads. That scenario was one main thread manually...
4
by: christian.siegl | last post by:
Hello, I need a buffer reinitialized approx. once in each second (I think this is quite often). Now I think to do the reinit within a separate thread (I am using boost::thread). Well, filling...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
3
by: stumorgan | last post by:
Basically what I have is a form with a graph on it which graphs data that I'm reading from a USB device at 100 Hz (every 10ms). I have a thread reading and parsing the data from the USB, but when...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
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
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...
0
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...

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.