GUI refreshing??rendering?? (basic question..)

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have an application that scans files and it takes a while to finish. While
my application is running if I open other applications, my main application
GUI becomes grey....does not refresh or render itself. It becomes clear only
after finishing the scan.

Is there a way of refreshing the GUI? or rendering it again continously? ( I
am not sure if I am using the correct terms, but I hope somebody understands
my problem)

Any help appreciated
 
Hello John!
Put file scanning code in another thread (other than UI thread), and if
you want to display any progress on the UI, use Invoke method of your
WinForm.
I hope it solves your problem.
Bye!

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 
John said:
I have an application that scans files and it takes a while to finish. While
my application is running if I open other applications, my main application
GUI becomes grey....does not refresh or render itself. It becomes clear only
after finishing the scan.

Is there a way of refreshing the GUI? or rendering it again continously? ( I
am not sure if I am using the correct terms, but I hope somebody understands
my problem)

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
 
Alternatively, Application.DoEvents ();

use it periodically while scanning for files.

However, the drawback is that it may decrease the performance of scanning
files.
for example:

loop {

if (num of files scanned % 100 == 0){
Application.DoEvents();
}
...continue scan for files...
}
 
Bern said:
Alternatively, Application.DoEvents ();

use it periodically while scanning for files.

Aargh, no :)

DoEvents is, IMO, a horrible hack to "fake" proper multi-threading.
When real multi-threading is already available in the framework, I
think it's best to avoid DoEvents with its problems (potential re-
entrancy and having to guess how often to call it, for starters).
 
What you do John, is that you spawn off a background thread to do the
actual work. That way, the GUI thread (which is responsible for the
rendering) is free to maintain it's visuals. This method also have a
few other benefits such as being able to provide pause, resume, and
cancel functionality for your long running process.

Here's an article on threading in C# in case you need it.
http://www.codeproject.com/csharp/Multithreading_In_C_.asp

Good luck,
Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog
 
Back
Top