Threading question

Jayson

Member
Joined
Jun 3, 2008
Messages
10
Programming Experience
1-3
I am trying to wrap my head around threads.

I have a recursive method that displays directory paths in a multiline text box. The directory structure is very large, about 20000 folders up to around 20 levels deep on some branches.

I have been getting a ContextSwitchingDeadlock error from time to time. I understand that this error can be supressed via a setting (somewhere) in VS2005. I though it would be better to run my recursive method on it's own thread instead of supressing the message??

My method (GetTree) accepts one parameter, a start directory. I've been trying to declare the tread as follows,

Dim t As New Thread(New ThreadStart(AddressOf Me.GetTree(StartDir)))

But this gives me the error "AddressOf operand must be the name of the method without parentheses"

If I try the same thing using another method that takes no arguments it's no problem.

What am I doing wrong?
 
Use the BackgroundWorker instead of handling the threading on your own.

In VS 2005 and VS 2008 it's right in the ToolBox, drop it on your form and put your separate-thread code in the BW's DoWork() event
 
I am trying to wrap my head around threads.
I have been getting a ContextSwitchingDeadlock error from time to time.

If it is any consolation, I have only encountered this while running apps within visual studio, as annoying as it is I don't think this occurs when you invoke your compiled executable. I would like a real 'fix' to address the core issue myself, till I find that..... Let me know if your experience differs.
 
Thanks for the info. I've also only seen this while running in VS and I had turned it off (on another machine) via a switch inside an exception configuration setting. Can't seem to find the darn thing again :-(
 
Back
Top