G
Guest
I am trying to pop a dialog box from a thread but I run into problems so far. At the beginning My MainForm pops up a ActiveDlg during the MainForm_OnLoad, and stay as is. Then later a thread listening a socket triggers an event that must pop up a EventDlg form, no matter which form is active on the screen. In the near future, I may have dozens of form (let us say similar to ActiveDlg) that can be poped up by the MainForm.
The problem I have here is related to compact Framework. On desktop computers, this example is working well but not with .NET framework on Pocket PC 2003. What happens here is that the EventDlg pops up only if there is no ActiveDlg on the screen. If there is one, it will wait until the ActiveDlg is closed before being shown on the screen
The problem of using Show instead of ShowDialog is that it will be not possible to close the dialog box: by checking the tasklist running on the PocketPC (Memory setting/Running Task), it accumulates all dialog box created with Form.Show(). Does anybody have some hint to get rid of this problem when using ShowDialog()
Here is a sample program that reproduces the problem I have. The listening thread is void ListeningThread() and I created 2 basic forms: one active and the other one specific the event
Thank you for all advice
Regards
Cyri
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System
using System.Drawing
using System.Collections
using System.Windows.Forms
using System.Data
using System.Threading
namespace TestXX
/// <summary
/// Summary description for Form1
/// </summary
///
public delegate void InvokeDelegate(object obj, System.EventArgs e)
public class MainForm : System.Windows.Forms.For
private System.Windows.Forms.MainMenu mainMenu1
public MainForm(
/
// Required for Windows Form Designer suppor
/
InitializeComponent()
/
// TODO: Add any constructor code after InitializeComponent cal
/
/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing
base.Dispose( disposing )
#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.mainMenu1 = new System.Windows.Forms.MainMenu()
//
// MainFor
//
this.Menu = this.mainMenu1
this.Text = "Initial form"
this.Load += new System.EventHandler(this.Form1_Load)
#endregio
/// <summary
/// The main entry point for the application
/// </summary
static void Main()
Application.Run(new MainForm())
void ShowEventDlg(object obj, System.EventArgs e
{
EventDlg dlg = new EventDlg()
dlg.ShowDialog()
private void Form1_Load(object sender, System.EventArgs e
ActiveDlg dlg = new ActiveDlg()
Thread t = new Thread(new ThreadStart(ListeningThread))
t.Start();
dlg.ShowDialog()
void ListeningThread()
System.Threading.Thread.Sleep(2000)
InvokeDelegate xxx = new InvokeDelegate(ShowEventDlg)
this.Invoke(new System.EventHandler(xxx));
public class EventDlg : System.Windows.Forms.For
private System.Windows.Forms.Button button1
public EventDlg(
InitializeComponent()
/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing
base.Dispose( disposing )
#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.button1 = new System.Windows.Forms.Button()
//
// button
//
this.button1.Location = new System.Drawing.Point(40, 24)
this.button1.Text = "Close"
this.button1.Click += new System.EventHandler(this.button1_Click)
//
// EventDlg
//
this.Controls.Add(this.button1);
this.Text = "EventDlg";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
public class ActiveDlg : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
public ActiveDlg()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 16);
this.button1.Text = "Close";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// ActiveDlg
//
this.Controls.Add(this.button1);
this.Text = "ActiveDlg";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
The problem I have here is related to compact Framework. On desktop computers, this example is working well but not with .NET framework on Pocket PC 2003. What happens here is that the EventDlg pops up only if there is no ActiveDlg on the screen. If there is one, it will wait until the ActiveDlg is closed before being shown on the screen
The problem of using Show instead of ShowDialog is that it will be not possible to close the dialog box: by checking the tasklist running on the PocketPC (Memory setting/Running Task), it accumulates all dialog box created with Form.Show(). Does anybody have some hint to get rid of this problem when using ShowDialog()
Here is a sample program that reproduces the problem I have. The listening thread is void ListeningThread() and I created 2 basic forms: one active and the other one specific the event
Thank you for all advice
Regards
Cyri
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System
using System.Drawing
using System.Collections
using System.Windows.Forms
using System.Data
using System.Threading
namespace TestXX
/// <summary
/// Summary description for Form1
/// </summary
///
public delegate void InvokeDelegate(object obj, System.EventArgs e)
public class MainForm : System.Windows.Forms.For
private System.Windows.Forms.MainMenu mainMenu1
public MainForm(
/
// Required for Windows Form Designer suppor
/
InitializeComponent()
/
// TODO: Add any constructor code after InitializeComponent cal
/
/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing
base.Dispose( disposing )
#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.mainMenu1 = new System.Windows.Forms.MainMenu()
//
// MainFor
//
this.Menu = this.mainMenu1
this.Text = "Initial form"
this.Load += new System.EventHandler(this.Form1_Load)
#endregio
/// <summary
/// The main entry point for the application
/// </summary
static void Main()
Application.Run(new MainForm())
void ShowEventDlg(object obj, System.EventArgs e
{
EventDlg dlg = new EventDlg()
dlg.ShowDialog()
private void Form1_Load(object sender, System.EventArgs e
ActiveDlg dlg = new ActiveDlg()
Thread t = new Thread(new ThreadStart(ListeningThread))
t.Start();
dlg.ShowDialog()
void ListeningThread()
System.Threading.Thread.Sleep(2000)
InvokeDelegate xxx = new InvokeDelegate(ShowEventDlg)
this.Invoke(new System.EventHandler(xxx));
public class EventDlg : System.Windows.Forms.For
private System.Windows.Forms.Button button1
public EventDlg(
InitializeComponent()
/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing
base.Dispose( disposing )
#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.button1 = new System.Windows.Forms.Button()
//
// button
//
this.button1.Location = new System.Drawing.Point(40, 24)
this.button1.Text = "Close"
this.button1.Click += new System.EventHandler(this.button1_Click)
//
// EventDlg
//
this.Controls.Add(this.button1);
this.Text = "EventDlg";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
public class ActiveDlg : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
public ActiveDlg()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 16);
this.button1.Text = "Close";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// ActiveDlg
//
this.Controls.Add(this.button1);
this.Text = "ActiveDlg";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}