Handle Application.DoEvents()

csharp , java , sqlserver Ţungī, Bangladesh
  • 8 years ago
    I've created a windows application which shows change of label text.I use loop to increment value from 1 to 100 and that shows in a label.For showing that I use Application.DoEvents() method.But I need to cancel that operation after clicking on close button.But after I clicking on close button it only close form but not the operation.Also it need to click twice on the "Close" button.Single click doesn't work. namespace TestApp { public partial class FrmTest : Form { public FrmTest() { InitializeComponent(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void btnProcess_Click(object sender, EventArgs e) { for (int i = 1; i <= 100000; i++) { this.lblText.Text = i.ToString(); Application.DoEvents(); //System.Threading.Thread.Sleep(200); } btnMsg.MouseClick += new MouseEventHandler(btnMsg_Click); } private void btnMsg_Click(object sender, EventArgs e) { MessageBox.Show(sender.ToString()); MessageBox.Show(e.ToString()); } } }

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou