-
long loop problem
hello guys,
i'm writing a windows application. once the user click on a button, i will run a loop. the loop will take a long time to finish, and during the execution the program looks like dead. i want my application can still response to user input, what do i do?
thanks.
plus, i saw a warning every time i run the program saying that the program doesn't respond. everything is actually ok, i just click continue, everything will be fine. but the warning is still annoying. how should i deal with that.
the warning shows up when i debug the code. i don't know if it will still show up if i compile it as a release mode.
-
Re: long loop problem
This is quite simple,
just use the BackgroundWorker Thread, or the "usual" threads as follows:
Code:
using System;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void MyThread()
{
// do something loop-ish here
}
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(MyThread));
thread.Start();
}
}
}
The thread runs independently and does not freeze your GUI.
-
Re: long loop problem
-
Re: long loop problem
this tutorial is great, now I finally understand how the messages work, thx BigEd781