I'm having problem closing a form after handling a FlashCall.
After reading some on the forum here I found this topic:
External interface & Form.Close() Problem
In the last post by ovidiu he gives the following solution:
try setting a private variable on your form called closeWhenIdle, which is initially set to false. when u call the method from flash, set this variable to true and do nothing else
next, make sure that in the load event of your form u register the following event:
Application.Idle += new EventHandler(Application_Idle);
this event handler is called continuously when the application has nothing to do in terms of processing (don't worry about performance problems)
the method should look like this;Code: Select all
private void Application_Idle(object sender, EventArgs e)
{
if (this.CloseWhenIdle)
{
this.Close();
// useful when the OnClosing method was ovverridden
// and e.Cancel was set to true inside of it
this.CloseWhenIdle = false;
}
}
But for some reason this doesn't work for me. Here's my document, please tell me if you see anything wrong with it.
Code: Select all
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Xml;
namespace Pausit
{
/// <summary>
/// Summary description for FormIntro.
/// </summary>
public class FormIntro : f_in_box__lib.f_in_box__form
{
private bool CloseWhenIdle = false;
private FormSettings m_parent;
public FormIntro(FormSettings frm1)
{
//
// TODO: Add constructor logic here
//
InitializeComponent();
m_parent = frm1;
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// FormIntro
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(200, 200);
this.Context = "private";
this.Name = "FormIntro";
this.ShowInTaskbar = false;
this.Text = "Pausit";
this.Load += new System.EventHandler(this.FormIntro_Load);
this.OnFlashCall += new f_in_box__lib.f_in_box__form.OnFlashCallEventHandler(this.FormIntro_OnFlashCall);
this.ResumeLayout(false);
}
private void FormIntro_Load(object sender, EventArgs e)
{
Application.Idle += new EventHandler(Application_Idle);
}
private void FormIntro_OnFlashCall(object sender, string request)
{
string strCommand;
XmlDocument FlashXMLDoc = new XmlDocument();
FlashXMLDoc.LoadXml(request);
strCommand = FlashXMLDoc.GetElementsByTagName("invoke").Item(0).Attributes.GetNamedItem("name").Value;
if (strCommand == "ExitIntro")
{
CloseWhenIdle = true;
}
else if (strCommand == "StartExercise")
{
//MessageBox.Show("StartExercise");
m_parent.ShowExercises();
}
}
private void Application_Idle(object sender, EventArgs e)
{
if (this.CloseWhenIdle)
{
this.Close();
this.CloseWhenIdle = false;
}
}
}
}
Appreciate any help I can get.