473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Debugging thread problem

Hi there,

Has anyone had any problems debugging a thread in VS 2005. If I put a
breakpoint on a worker thread (the only one in the app) and then run the app
two things happen:

1) It takes an unusually long time for the breakpoint to kick in once
encountered
2) When it finally does break, I can't step through any code. As soon as I
try, the debugger just runs off somewhere and never returns control to me.

Any suggestions? Thanks..
Sep 14 '06 #1
9 6134
Update:

Unless there's some way to corrupt memory in C#/.NET (I'm relatively new to
it but very experienced in C/C++), this appears to be a VS bug though any
feedback would still be appreciated. That is, if I situate my breakpoint
earlier in the code I can debug no problem. If I then move the breakpoint
ahead one line at time, I eventually reach a point where the problem
suddenly surfaces. This occurs when I move the breakpoint to the first line
of a function outside the file where the thread actually starts. As soon as
I try to step into that function, the debugger takes about 20 seconds to do
so and when it finally does break, I can no longer step at all since the
debugger never returns. At one point I did notice a very brief message flash
on the bottom of the screen (in a small yellow window) to the effect that VS
was waiting for some internal operation to finish or something like that (it
flashed too quicly too digest it all). Anyway, this is a serious problem if
I can't debug my thread so any input would be welcome. Thanks.
Sep 14 '06 #2

"John Brown" <no_spam@_nospam.comwrote in message
news:Od**************@TK2MSFTNGP03.phx.gbl...
| Hi there,
|
| Has anyone had any problems debugging a thread in VS 2005. If I put a
| breakpoint on a worker thread (the only one in the app) and then run the
app
| two things happen:
|
| 1) It takes an unusually long time for the breakpoint to kick in once
| encountered
| 2) When it finally does break, I can't step through any code. As soon as I
| try, the debugger just runs off somewhere and never returns control to me.
|
| Any suggestions? Thanks..
|
|

What kind of application is this? Windows forms or console like.
If Windows forms, do you pass the form object to the other thread?

Willy.
Sep 14 '06 #3
What kind of application is this? Windows forms or console like.
If Windows forms, do you pass the form object to the other thread?
Well, the worker thread's main function (entry point) is a member of a
"Form" derivative and it passes a reference to the enclosing object (form)
to a function in another file and that's exactly where things start failing
(as soon as the latter function is called). However, note that all GUI
processing is being routed back to the main GUI thread via
"Control.Invoke()". In any case, is there a reason it should fail as soon
that function is called (perhaps you're alluding to some marshalling issue I
haven't considered - does the form's reference need to be marshalled to the
thread in some way). Thanks for your assistance (appreciated).
Sep 14 '06 #4

I've noticed this problem when stepping from code we have source for
to code we don't have source for (a 3rd party dll) when the other code
was compiled width debugging enabled. I most often run into this when
debugging unit tests and I step past the end of one test and control
returns to the test framework.

Does the problem occur always on a particular line of code? What
happens if instead of stepping into this line you step over it? Can
you set a breakpoint later in the program and it works ok (past the
offending line)?

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.


On Thu, 14 Sep 2006 18:07:36 -0400, "John Brown" <no_spam@_nospam.com>
wrote:
>Update:

Unless there's some way to corrupt memory in C#/.NET (I'm relatively new to
it but very experienced in C/C++), this appears to be a VS bug though any
feedback would still be appreciated. That is, if I situate my breakpoint
earlier in the code I can debug no problem. If I then move the breakpoint
ahead one line at time, I eventually reach a point where the problem
suddenly surfaces. This occurs when I move the breakpoint to the first line
of a function outside the file where the thread actually starts. As soon as
I try to step into that function, the debugger takes about 20 seconds to do
so and when it finally does break, I can no longer step at all since the
debugger never returns. At one point I did notice a very brief message flash
on the bottom of the screen (in a small yellow window) to the effect that VS
was waiting for some internal operation to finish or something like that (it
flashed too quicly too digest it all). Anyway, this is a serious problem if
I can't debug my thread so any input would be welcome. Thanks.
Sep 14 '06 #5
I've noticed this problem when stepping from code we have source for
to code we don't have source for (a 3rd party dll) when the other code
was compiled width debugging enabled. I most often run into this when
debugging unit tests and I step past the end of one test and control
returns to the test framework.

Does the problem occur always on a particular line of code? What
happens if instead of stepping into this line you step over it? Can
you set a breakpoint later in the program and it works ok (past the
offending line)?
I can step all over the function in file 1 anyway I like but as soon as I
call a function in file 2 the problem starts (I own all source). Willy may
be on to something however since I just discovered that the problem stops
when I pass "null" to the offending function in file 2 instead of the "Form"
reference I normally pass. I think there may be some marshalling issue here
perhaps (with the form's reference). The situation is quite simple however.
A form starts the worker thread going in its "OnLoad()" handler by invoking
"BackgroundWorker.RunWorkerAsync()" (standard 2.0 class). The worker thread
(another function in the form's class) then passes "this" to a function in
another file. That's when all the trouble starts. The debugger goes away for
a 20 second smoke (or whatever it's doing) and then it finally breaks at the
first line in the latter function. At this point however I can't step any
further without the debugger going into la la land permanently. Passing
"null" instead of "this" however eliminates the problem. I thought that
perhaps instead of passing "this", maybe I need to marshal the form's
pointer to the thread somehow but if so then it's news to me (I'm relatively
new to C# and .NET though very experienced in C/C++). Any thoughts?
Sep 15 '06 #6
>What kind of application is this? Windows forms or console like.
>If Windows forms, do you pass the form object to the other thread?

Well, the worker thread's main function (entry point) is a member of a
"Form" derivative and it passes a reference to the enclosing object (form)
to a function in another file and that's exactly where things start
failing (as soon as the latter function is called). However, note that all
GUI processing is being routed back to the main GUI thread via
"Control.Invoke()". In any case, is there a reason it should fail as soon
that function is called (perhaps you're alluding to some marshalling issue
I haven't considered - does the form's reference need to be marshalled to
the thread in some way). Thanks for your assistance (appreciated).
By sheer coincidence I came across the following link while pursuing another
matter related to this problem (what luck!). I'm still tinkering but the
"DebuggerDisplay" attribute seems to have solved the problem for the moment.
See the "System.Windows.Forms.Form and multithreading" section here:

http://blogs.msdn.com/greggm/archive...18/494648.aspx
Sep 15 '06 #7
John,

Although in VB.Net do I have the same problem. I hope that this is one of
the fixes done in the next service pack, because this makes multithreading
not fine to use at the moment in my idea. My screen is completely blanked
out in those cases.

(The Microsoft development debugger team is AFAIK the same for C# and
VB.Net).

Cor

"John Brown" <no_spam@_nospam.comschreef in bericht
news:Od**************@TK2MSFTNGP03.phx.gbl...
Hi there,

Has anyone had any problems debugging a thread in VS 2005. If I put a
breakpoint on a worker thread (the only one in the app) and then run the
app two things happen:

1) It takes an unusually long time for the breakpoint to kick in once
encountered
2) When it finally does break, I can't step through any code. As soon as I
try, the debugger just runs off somewhere and never returns control to me.

Any suggestions? Thanks..

Sep 15 '06 #8

"John Brown" <no_spam@_nospam.comwrote in message
news:ua**************@TK2MSFTNGP06.phx.gbl...
| >What kind of application is this? Windows forms or console like.
| >If Windows forms, do you pass the form object to the other thread?
| >
| Well, the worker thread's main function (entry point) is a member of a
| "Form" derivative and it passes a reference to the enclosing object
(form)
| to a function in another file and that's exactly where things start
| failing (as soon as the latter function is called). However, note that
all
| GUI processing is being routed back to the main GUI thread via
| "Control.Invoke()". In any case, is there a reason it should fail as
soon
| that function is called (perhaps you're alluding to some marshalling
issue
| I haven't considered - does the form's reference need to be marshalled
to
| the thread in some way). Thanks for your assistance (appreciated).
|
| By sheer coincidence I came across the following link while pursuing
another
| matter related to this problem (what luck!). I'm still tinkering but the
| "DebuggerDisplay" attribute seems to have solved the problem for the
moment.
| See the "System.Windows.Forms.Form and multithreading" section here:
|
| http://blogs.msdn.com/greggm/archive...18/494648.aspx
|
|

Righht John, that's exactly what you are after, I hope one of the
work-arounds will help you out.

Willy.
Sep 15 '06 #9
Righht John, that's exactly what you are after, I hope one of the
work-arounds will help you out.
So far so good. Thanks for your help. Hopefully MSFT will get around to
repairing this situation as I'm sure many others have endured the same
frustration.
Sep 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Elbert Lev | last post by:
I started with Python two weeks ago and already saved some time and efforts while writing 2 programs: 1. database extraction and backup tool, which runs once a month and creates a snapshot of...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Bruno van Dooren | last post by:
Hi, i was debugging a multithreaded app, when i stumbled across some weird behavior of the debugger. in the destructor of my main object i send a stop event to the worker thread, and then...
3
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
4
by: Nadav Popplewell | last post by:
Hi Everybody, I've got a problem debugging ASP.NET applications on an XP SP2 System. The Details: Up to now I've been developing on an XP SP1 computer. Several days ago I got a new computer...
1
by: DEWright_CA | last post by:
I have built a pretty basic site and now when I try t debug it I get a error that says; {0}: Build (web): "The type initializer for 'System.Web.Compilation.CompilationLock' threw an exceptoin. ...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
10
by: Doug Robertson | last post by:
First off, I'm a hardware/OS guy. I just write code on the side and I'm completely self taught - so bear in mind my total lack of expertise. I have a program originally written in VB2003 using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.