|
-
June 15th, 2009, 11:50 PM
#1
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.
-
June 16th, 2009, 12:23 AM
#2
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.
-
June 16th, 2009, 02:06 AM
#3
-
June 20th, 2009, 02:34 PM
#4
Re: long loop problem
this tutorial is great, now I finally understand how the messages work, thx BigEd781
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|