T
TS
I want to be able to display a modal window during my application used to
take tests. The application has a looping timer that after each time it's
interval elapses, an event is raised that checks the db to see if a field in
a table is marked as being paused meaning someone in my other app has marked
the test as being paused. i want the modal window to pop up if so, unless
the window is already displayed becuase of the last time the timer elapsed.
I want the modal window to dissappear if it is visible and the test has been
un-paused. I have it working except that for some reason after the first
call to showDialog(), the code doesn't continue to execute the rest of the
method, instead it starts back at the top again. There are no exceptions
that are being thrown becuase it is wrapped in a try/catch. When the code at
the beg. of the method begins again, the reference to the modal form that is
modularly declared is null. After the 2nd time thru the method, everything
works as expected.
Why is this?
this is the event that is fired when the timer's interval is gone on the
main form.
private void TerminateTimer_Tick(object sender, EventArgs e)
{
try
{
string status = this.MyController.GetApplicantStatus();
if( status == "H" ) //Hold
{
if(this.pause == null)
{
pause = new Pause();
pause.ShowDialog();
}
}
else if( status == "T" ) //Terminated
{
if(this.pause != null)
pause.Close();
this.terminateTimer.Stop();
this.MyController.TerminateSession();
}
else
{
if(this.pause != null)
{
pause.Close();
pause.Dispose();
}
}
string x="asdfasdf";
}
catch(Exception ex)
{
ReportException(ex);
}
}
this is the form that is displayed as a modal window:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Shared.ResourceHelper;
namespace TestStationUI
{
/// <summary>
/// Summary description for Pause.
/// </summary>
public class Pause : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblPauseMessage;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Pause()
{
//
// 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 )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
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.lblPauseMessage = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblPauseMessage
//
this.lblPauseMessage.Location = new System.Drawing.Point(32, 40);
this.lblPauseMessage.Name = "lblPauseMessage";
this.lblPauseMessage.Size = new System.Drawing.Size(216, 40);
this.lblPauseMessage.TabIndex = 0;
//
// Pause
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.lblPauseMessage);
this.Name = "Pause";
this.Text = "Pause";
this.Load += new System.EventHandler(this.Pause_Load);
this.ResumeLayout(false);
}
#endregion
private void Pause_Load(object sender, System.EventArgs e)
{
this.lblPauseMessage.Text =
ResManager.GetText(this.lblPauseMessage.Name);
}
}
}
take tests. The application has a looping timer that after each time it's
interval elapses, an event is raised that checks the db to see if a field in
a table is marked as being paused meaning someone in my other app has marked
the test as being paused. i want the modal window to pop up if so, unless
the window is already displayed becuase of the last time the timer elapsed.
I want the modal window to dissappear if it is visible and the test has been
un-paused. I have it working except that for some reason after the first
call to showDialog(), the code doesn't continue to execute the rest of the
method, instead it starts back at the top again. There are no exceptions
that are being thrown becuase it is wrapped in a try/catch. When the code at
the beg. of the method begins again, the reference to the modal form that is
modularly declared is null. After the 2nd time thru the method, everything
works as expected.
Why is this?
this is the event that is fired when the timer's interval is gone on the
main form.
private void TerminateTimer_Tick(object sender, EventArgs e)
{
try
{
string status = this.MyController.GetApplicantStatus();
if( status == "H" ) //Hold
{
if(this.pause == null)
{
pause = new Pause();
pause.ShowDialog();
}
}
else if( status == "T" ) //Terminated
{
if(this.pause != null)
pause.Close();
this.terminateTimer.Stop();
this.MyController.TerminateSession();
}
else
{
if(this.pause != null)
{
pause.Close();
pause.Dispose();
}
}
string x="asdfasdf";
}
catch(Exception ex)
{
ReportException(ex);
}
}
this is the form that is displayed as a modal window:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Shared.ResourceHelper;
namespace TestStationUI
{
/// <summary>
/// Summary description for Pause.
/// </summary>
public class Pause : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblPauseMessage;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Pause()
{
//
// 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 )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
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.lblPauseMessage = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblPauseMessage
//
this.lblPauseMessage.Location = new System.Drawing.Point(32, 40);
this.lblPauseMessage.Name = "lblPauseMessage";
this.lblPauseMessage.Size = new System.Drawing.Size(216, 40);
this.lblPauseMessage.TabIndex = 0;
//
// Pause
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.lblPauseMessage);
this.Name = "Pause";
this.Text = "Pause";
this.Load += new System.EventHandler(this.Pause_Load);
this.ResumeLayout(false);
}
#endregion
private void Pause_Load(object sender, System.EventArgs e)
{
this.lblPauseMessage.Text =
ResManager.GetText(this.lblPauseMessage.Name);
}
}
}