473,373 Members | 1,179 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,373 software developers and data experts.

[Q]Multi-Threaded Splash Screen not displaying first update.

Dear Group,

I am attempting to write a "splash" and "status" Form using a second
thread.

I wish to use this Form to display status information to the user when
I do CPU intensive work in my GUI during startup. I wish to also use
the same Form after startup as well if I do something CPU intensive.

I have developed a multi-threaded application however the very first
status update does not always display. It sometimes appears which I
am assuming is to do with the interaction of my two threads.

Could anyone comment on what I have missed that causes the "Startup
Point 1" and "Running Point 1" status labels to sometimes display and
others not.

I have included the following cutdown example of what I am doing.
There are two files ApplicationLoader.cs and MainApplicationForm.cs.
Run the application to see the startup screen and press the button to
see the running version. Note the first status information label
shown.

Any comments would be most appreciated.

Thanks

Stuart

------Start ApplicationLoader.cs------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;

namespace startupscreen
{
public class statusInformationForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label statusInformation;
private System.Windows.Forms.Label statusTitleLabel;

private System.ComponentModel.Container components = null;

public statusInformationForm()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private string theStatusInfo = String.Empty;
public string StatusInfo
{
set
{
theStatusInfo = value;
updateStatusText();
}
get
{
return theStatusInfo;
}
}

public void updateStatusText()
{
try
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(this.updateStatusText));
return;
}

statusInformation.Text = theStatusInfo;
}
catch (Exception e)
{
}
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.statusInformation = new System.Windows.Forms.Label();
this.statusTitleLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// statusInformation
//
this.statusInformation.Location = new System.Drawing.Point(80, 40);
this.statusInformation.Name = "statusInformation";
this.statusInformation.Size = new System.Drawing.Size(200, 16);
this.statusInformation.TabIndex = 1;
//
// statusTitleLabel
//
this.statusTitleLabel.Location = new System.Drawing.Point(16, 40);
this.statusTitleLabel.Name = "statusTitleLabel";
this.statusTitleLabel.Size = new System.Drawing.Size(48, 16);
this.statusTitleLabel.TabIndex = 2;
this.statusTitleLabel.Text = "Status:";
//
// statusInformationForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(300, 94);
this.ControlBox = false;
this.Controls.Add(this.statusTitleLabel);
this.Controls.Add(this.statusInformation);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "statusInformationForm";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.ResumeLayout(false);

}
#endregion
}

public class ApplicationLoader
{
[STAThread]
static void Main(string[] args)
{
MainApplicationForm mainApplicationForm = new
MainApplicationForm();
Application.Run(mainApplicationForm);
}
}
public class statusInformationScreen
{
private static statusInformationForm theStatusInformationForm =
null;
private static Thread statusInformationThread = null;

private static void ShowThread()
{
theStatusInformationForm = new statusInformationForm();
Application.Run(theStatusInformationForm);
}

public static void Show()
{
if (statusInformationThread != null)
return;

statusInformationThread = new Thread(new
ThreadStart(statusInformationScreen.ShowThread));
statusInformationThread.IsBackground = true;
statusInformationThread.ApartmentState = ApartmentState.STA;
statusInformationThread.Start();
}

public static void Close()
{
if (statusInformationThread == null || theStatusInformationForm ==
null)
{
statusInformationThread = null;
theStatusInformationForm = null;
return;
}
try
{
theStatusInformationForm.Invoke(new
MethodInvoker(theStatusInformationForm.Close));
}
catch (Exception)
{
}
statusInformationThread = null;
theStatusInformationForm = null;
}

public static string Status
{
set
{
if (theStatusInformationForm == null)
{
return;
}
theStatusInformationForm.StatusInfo = value;
}
get
{
if (theStatusInformationForm == null)
{
throw new InvalidOperationException("Form not visible?");
}
return theStatusInformationForm.StatusInfo;
}
}
}
}
------End ApplicationLoader.cs------------
------Start MainApplicationForm.cs--------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace startupscreen
{
public class MainApplicationForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button Button;
private System.ComponentModel.Container components = null;

public MainApplicationForm()
{
InitializeComponent();

statusInformationScreen.Show();
//
// This status information is not ALWAYS displayed
//
statusInformationScreen.Status = "Startup Point 1";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Status = "Startup Point 2";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Status = "Startup Point 3";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Close();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
this.Button = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Button
//
this.Button.Location = new System.Drawing.Point(72, 88);
this.Button.Name = "Button";
this.Button.Size = new System.Drawing.Size(136, 96);
this.Button.TabIndex = 0;
this.Button.Text = "Push Me";
this.Button.Click += new System.EventHandler(this.button_Click);
//
// MainApplicationForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.Button);
this.Name = "MainApplicationForm";
this.Text = "My Form";
this.ResumeLayout(false);

}
#endregion

protected override void OnLoad(System.EventArgs e)
{
this.Activate();
}

private void button_Click(object sender, System.EventArgs e)
{
statusInformationScreen.Show();
//
// This status information is not ALWAYS displayed
//
statusInformationScreen.Status = "Running Point 1";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Status = "Running Point 2";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Status = "Running Point 3";
System.Threading.Thread.Sleep(2000);

statusInformationScreen.Close();
}
}
}
------End MainApplicationForm.cs--------
Nov 16 '05 #1
0 1793

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

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
2
by: Aussie Rules | last post by:
Hi, I have a site that Iwant to either display my text in english or french, based on the users prefernces ? I am new to webforms, but I know in winforms, this is pretty easy with a resource...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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.