ShowDialog blocks execution of a form from which it is invoked. If you want
to show multiple child dialogs, use Show instead
"cyril" <(E-Mail Removed)> wrote in message
news:0A0AD3D4-2F3F-4A57-B3F5-(E-Mail Removed)...
> 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 advices
> Regards,
> Cyril
>
>
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
> using System;
> using System.Drawing;
> using System.Collections;
> using System.Windows.Forms;
> using System.Data;
>
> using System.Threading;
>
> namespace TestXXX
> {
> /// <summary>
> /// Summary description for Form1.
> /// </summary>
> ///
> public delegate void InvokeDelegate(object obj, System.EventArgs e);
>
> public class MainForm : System.Windows.Forms.Form
> {
> private System.Windows.Forms.MainMenu mainMenu1;
>
> public MainForm()
> {
> //
> // Required for Windows Form Designer support
> //
> InitializeComponent();
>
> //
> // TODO: Add any constructor code after InitializeComponent call
> //
> }
> /// <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.mainMenu1 = new System.Windows.Forms.MainMenu();
> //
> // MainForm
> //
> this.Menu = this.mainMenu1;
> this.Text = "Initial form";
> this.Load += new System.EventHandler(this.Form1_Load);
>
> }
> #endregion
>
> /// <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.Form
> {
> 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 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, 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();
> }
> }
> }
>
|