what can i do?
here is my code:
private void thread_DoWork(object sender, DoWorkEventArgs e)
{
foreach(string path in this.Paths) // 'Paths' is a List<string>
{
if(Directory.Exists(path))
RecurseFolder(path);
else if(File.Exists(path))
this.thread.ReportProgress(0, path);
}
}
private void RecurseFolder(string path)
{
// ...
}
private void thread_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
this.txt1.Text += e.UserState.ToString() + "\r\n";
}
thanks
tim
// **** try adding the line below it should
// cause the TextBox to update
// ****
Application.DoEvents();
>}
>
>thanks
>tim
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
there are 400 files and folders that i'm scanning, this is not a
massive number, although they are read very quickly, 2 or 3 seconds.
i did find a way to work around it. if i call ScrollToCaret() or
Update() on the textbox, then it does update in real time, but the form
is still totally unresponsive during this time and it looks very poor,
with all the labels and buttons needing to be re-drawn.
Can you try this: (VB, Sorry)
Dim worker As BackGroundWorker = Directcast(sender, BackGroundWorker)
worker.ReportProgress(0, path)
or simply
DirectCast(sender, BackGroundWorker).ReportProgress(0, path)
I think the "this.thread" call might have something to do with it.
can you post what you are doing inside ReportProgress?
the code in Progress_Changed is as follows:
this.txtInclude.Text += e.UserState.ToString() + "\r\n";
to at least get the text box to update in real time, i changed it this:
this.txtInclude.Text += e.UserState.ToString() + "\r\n";
this.txtInclude.SelectionStart = this.txtInclude.Text.Length - 1;
this.txtInclude.ScrollToCaret();
i'm quite disappointed in the .net 2.0 Form stability. i can
understand that i am not exactly being kind to the form by shooting in
so many events, but i would have thought that UI responsiveness was
paramount whatever about if the textbox has time to render itself
between each method.
I belive you can eliminate the selectionstart and scrolltocaret too.
Let me know if this helps.
as a test, i added in Thread.Sleep(50) to the threading code in between
each iteration, and with this the form responds and updates properly.
i can only conclude that there are too many events for the form
rendering engine to cope with. bit of a shame.
thanks for your help, and i guess this is a disappointing conclusion
unless you have any suggestions.
tim
If it is too quick to render, then it is too quick to read.
Why update the UI on every event? Perhaps just update form variables
(presumably a string) in the event, and then update the UI from the
variables less frequently (say: every 200ms); you'd need to do a little
locking to prevent the events changing the variables while you are updating
the UI, but other than that it could be a far more stable mechanism.
Marc
(the UI update could be done using something as simple as a timer control)
Marc
your bulk update approach is a good idea. thanks.