1. Thread and GUI update problem
To all,
I have a GUI program (use c#), and I have create a Thread for loading
some bulk data, I also arrange the GUI program like this:
1) load a form showing "Wait for loading..." etc
2) a Thread is then created to load the bulk data
3) after the thread has completed, close the "Wait for loading" form
4) show the main form for the GUI program
The problem is that if I show the "waiting" form, that form's GUI will
not work properly (no repaint event and hangs around, ie. a blank
window), the worse thing is that the Thread may not work properly too
(actually it will stop executing, waiting for locks, maybe ??)
But if I start the Thread without showing any forms; it works
perfectly ????!
What's wrong ?? (the same things happen under .Net Compact Framework)
[code snippet for the main GUI form]
public class Trial04_02 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
private Trial04_01 mFrmSplash;
private Thread mThr_Main;
private System.Windows.Forms.ListBox listBox1;
private CommonEngine02 mCEng;
public Trial04_02()
{
InitializeComponent();
init ();
}
private void InitializeComponent() {}
protected void init ()
{
// 1st show splash form
this.mFrmSplash = new Trial04_01 ();
//this.mFrmSplash.Show ();
// 2nd create a thread to load sth...
// CommonEngine02 is a class containing the
// data loading function
this.mCEng = new CommonEngine02 (); this.mThr_Main = new Thread
(new ThreadStart (this.mCEng.threadTask));
this.mThr_Main.Start ();
this.mThr_Main.Join ();
this.mFrmSplash.Close ();
// 3rd other setup(s)
// get back the loaded data
System.Collections.ArrayList oArr
= this.mCEng.getArr_Data ();
for (int i=0; i<oArr.Count; i++)
{
this.listBox1.Items.Add (oArr[i]);
}
this.Show ();
}
static void Main ()
{
Application.Run (new Trial04_02 ());
}
}
}
[/code]
From Jason (Kusanagihk)
2. Update GUI from RunWorkerCompleted - CSharp/C#
3. Multithreading and updating the GUI
Hi all,
I have a workerthread which notyfies the GUI through a delegate like this:
if (deviceInsertedDelegate) deviceInsertedDelegate(stringAddress);
Now in my Form's code I write code like this:
private delegate void DeviceInsertedCallback(string Address);
public void DeviceInserted(string Address)
{
if (this.label1.InvokeRequired)
{
Invoke(new DeviceInsertedCallback(DeviceInserted), new
object[] { Address });
}
else
{
label1.Text = "Login : " + Address;
}
}
Now my question is if it's possible not to have the code as above in my
form. Would it be possible to synchronize (or whatever) from within my
worker thread.
Thanks in advance,
Bart
4. Boilerplate example for updating GUI inside a C# Thread - CSharp/C#
5. c# and updating the gui from a thread
Hello,
I'm aware of the ways MS has recommended updating the gui from a
thread.
eg.
BeginInvoke(StartedExaminingFile, new object[] { file });
But, I really don't like this solution. The fact that you're passing an
array of objects means if the function signature changes, the invoke
would fail terribly.
With all the code-generation that goes on with .net (ie. datasets etc),
couldn't MS make a wrapper for this call? It just seems
uncharacteristic of .net to not strongly type the parameters,
considering the introduction of things like generics (and other
mechanisms for strongly typing).
6. Updating GUI controls from threads - CSharp/C#
7. Very Fast Updates to GUI - blank out
I have an application that does alot of work and calculations. It updates it's internal status on a windows form. When I debug single step the numbers appear just right on the form. When I run the program in normal mode the text boxes to which the info is displayed just blank out. Sometimes the entire form just turns all white. I get the impression that the updates are happening too fast or something like that. What's going on? Any ideas?