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

C# Windows Forms: GUI and multiple threads

42
Consider the following:
Expand|Select|Wrap|Line Numbers
  1. namespace TestingStuff
  2. {
  3.     public partial class MainForm : Form
  4.     {
  5.         ToolStripStatusLabel toolStripStatusLabel = new ToolStripStatusLabel();
  6.  
  7.         abstract class Tab
  8.         {
  9.             public TabPage tabPage;
  10.             protected MainForm form;
  11.             public virtual void Refresh() { }
  12.         }
  13.  
  14.         public MainForm()
  15.         {
  16.             TabPage tabPageInfo = new TabPage();
  17.             InfoTab info = new InfoTab(this, tabPageInfo);
  18.         }
  19.  
  20.         public void refreshGUI()
  21.         {
  22.             toolStripStatusLabel.Text = "OK";
  23.         }
  24.  
  25.     }
  26.  
  27.  
  28. public partial class MainForm
  29. {
  30.     class InfoTab : Tab
  31.     {
  32.         internal InfoTab(MainForm form, TabPage tab)
  33.         {
  34.             this.form = form;
  35.             this.tabPage = tab;    
  36.         }
  37.  
  38.  
  39.         public override void Refresh()
  40.         {
  41.             form.toolStripStatusLabel.Text = "Info";
  42.         }
  43.     }
  44. }
  45. }
If I wanted to start the InfoTab.Refresh() - method in a separate thread, how would I do that? And is then 'if(InvokeRequired)' checks and delegates required since I know you must never use any member of a Control on any thread other than the one that created it?

Any input to enlighten me is highly appreciated!
Cheers!
Nov 20 '07 #1
1 2587
Shashi Sadasivan
1,435 Expert 1GB
You could use a background worker to act as a thread for you.

the invoke required method should be used if you are changinf any UI based elements (that is elements owned in the main thread)
if that is false then you can change it, else I generally skip it.
Nov 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
4
by: Joey Powell | last post by:
Hello all. For a long time now I have been struggling with a .net Windows Forms problem. In several of my applications, I use the "Process" class from System.Diagnostics to accomplish various task...
3
by: Scott | last post by:
I have written windows applications using MFC for several years and have frequently used MFC techniques. Now I'm moving to C# .NET WinForm. Mostly C# books describes C# language (sometimes...
12
by: Brian Keating EI9FXB | last post by:
Hello all, Wonder what approach is used for this problem. I have a MDIApplication, the MDIClinets are to be in a seperate thread. So I've done something like this, // Create a new Show...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
6
by: billr | last post by:
I have developed a small API for taking care of a lot of boiler plate stuff in a multi formed windows application, for example setting up a messaging thread framework. New Forms, in the...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
6
by: Chris Marsh | last post by:
All I have a database table, changes to the data within which I am interested in acting on. The approach that I'm taking is to have the database update a file every time data is updated. This...
28
by: | last post by:
I have a multi threaded windows form application that runs great after calling Application.Run(). Application.Run is required for a COM component I a using in the app (required for message loop). ...
3
by: aagarwal8 | last post by:
Hi, I have a main form, which i use to open secondary forms. From the secondary form i need to open a Modal Window in such a way that, my secondary form is blocked, but i can still access my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.