Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: On paint in tabpage? Pin
Luc Pattyn13-Mar-11 13:35
sitebuilderLuc Pattyn13-Mar-11 13:35 
AnswerRe: On paint in tabpage? Pin
DaveyM6913-Mar-11 13:37
professionalDaveyM6913-Mar-11 13:37 
GeneralRe: On paint in tabpage? Pin
Software200713-Mar-11 13:47
Software200713-Mar-11 13:47 
GeneralRe: On paint in tabpage? Pin
DaveyM6913-Mar-11 13:53
professionalDaveyM6913-Mar-11 13:53 
Questionadd gps info to image Pin
behzadcp13-Mar-11 1:49
professionalbehzadcp13-Mar-11 1:49 
AnswerRe: add gps info to image Pin
Bernhard Hiller14-Mar-11 0:55
Bernhard Hiller14-Mar-11 0:55 
QuestionMain thread freezing while running a separate thread Pin
ShadowUz12-Mar-11 14:35
ShadowUz12-Mar-11 14:35 
AnswerRe: Main thread freezing while running a separate thread Pin
Luc Pattyn12-Mar-11 15:40
sitebuilderLuc Pattyn12-Mar-11 15:40 
Hi,

your code looks a bit weird to me. Here are some comments:

1.
AddFiles(label1.Text); is strictly not OK, you are touching a Control from a thread other than the main one. A better approach is to read label1.Text before launching the thread, then pass the string to it somehow (class member, or ThreadStart parameter).

2.
the progressbar code will never execute: progressBar1.InvokeRequired and listBox1.InvokeRequired are bound to have the same value, so either the first if block's return will fire, or both if blocks will be skipped.

3.
the whole threading approach is flawed: there really isn't any code running on the separate thread, all it does is cause the outermost AddFiles() to run on the main thread, so the hierarchical scan is all on the main thread (which will be very busy and uncapable of serving the GUI).
Solution: split the action in two parts, the first part scanning the file system and storing strings in a collection (all on the separate thread), the second part adding the collection's content to the ListBox.

4.
Lastly, this is a typical job a BackgroundWorker is good at. It would do the scanning in the DoWork handler, and the ListBox updating in the RunWorkerCompleted handler. You wouldn't need to call Invoke at all, the BGW does that for you.

PS: you may want to read this my little article[^] on the matter.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

Questionread and write Pin
om_metab12-Mar-11 12:53
om_metab12-Mar-11 12:53 
AnswerRe: read and write Pin
Richard MacCutchan12-Mar-11 22:51
mveRichard MacCutchan12-Mar-11 22:51 
AnswerRe: read and write, my vote of 1 (again) Pin
Keith Barrow12-Mar-11 23:32
professionalKeith Barrow12-Mar-11 23:32 
GeneralRe: read and write, my vote of 1 (again) Pin
Richard MacCutchan13-Mar-11 2:14
mveRichard MacCutchan13-Mar-11 2:14 
AnswerRe: read and write PinPopular
Pete O'Hanlon13-Mar-11 11:21
mvePete O'Hanlon13-Mar-11 11:21 
GeneralRe: read and write Pin
Dalek Dave13-Mar-11 11:23
professionalDalek Dave13-Mar-11 11:23 
QuestionHow disable scripts in webbrowser using c# Pin
shaozhufu12-Mar-11 3:11
shaozhufu12-Mar-11 3:11 
AnswerRe: How disable scripts in webbrowser by c# Pin
Dalek Dave12-Mar-11 3:49
professionalDalek Dave12-Mar-11 3:49 
GeneralRe: How disable scripts in webbrowser by c# Pin
shaozhufu12-Mar-11 4:14
shaozhufu12-Mar-11 4:14 
GeneralRe: How disable scripts in webbrowser by c# Pin
Dave Kreskowiak12-Mar-11 5:16
mveDave Kreskowiak12-Mar-11 5:16 
QuestionDeployment for Visual C# 2010 Express Pin
arkiboys11-Mar-11 19:43
arkiboys11-Mar-11 19:43 
AnswerRe: Deployment for Visual C# 2010 Express Pin
Luc Pattyn11-Mar-11 19:55
sitebuilderLuc Pattyn11-Mar-11 19:55 
GeneralRe: Deployment for Visual C# 2010 Express Pin
arkiboys11-Mar-11 19:59
arkiboys11-Mar-11 19:59 
AnswerRe: Deployment for Visual C# 2010 Express Pin
Luc Pattyn11-Mar-11 20:07
sitebuilderLuc Pattyn11-Mar-11 20:07 
AnswerRe: Deployment for Visual C# 2010 Express Pin
OriginalGriff12-Mar-11 2:34
mveOriginalGriff12-Mar-11 2:34 
GeneralRe: Deployment for Visual C# 2010 Express Pin
arkiboys12-Mar-11 5:10
arkiboys12-Mar-11 5:10 
GeneralRe: Deployment for Visual C# 2010 Express Pin
OriginalGriff12-Mar-11 5:16
mveOriginalGriff12-Mar-11 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.