4

I'm debugging C# code. The error is almost certainly not in the threadedness of the code, and would be just as erroneous in single threaded code.

How can I disable threading, or disable async/await processing, so I can not have to worry about switching threads when I'm trying to go through the processing?

EDIT: I want to do this because when I tell the program to go to the next line, it goes to a different line from what I'm expecting. It's possible that there's something really easy that I don't understand. But when I hit F11 / Step Into, it doesn't go to the next line in the code. Maybe I have too many breakpoints? Maybe I don't know the command to say "follow this thread"? I'm not sure what I'm doing wrong.

CindyH
  • 2,986
  • 2
  • 24
  • 38
  • 4
    There is no way to do this. Making a multi-threaded program suddenly single-threaded program is a sure recipe for deadlocks. – Stephen Cleary May 26 '16 at 23:03
  • 1
    If possible step over the new thread calls. alternatively you can chenge the threads to background threads which will not be debugged in the main thread – Shon May 26 '16 at 23:08
  • 1
    Besides the fact that async/await uses a task queue but (by default) no new threads. – Ben Voigt May 26 '16 at 23:34
  • 2
    What @StephenCleary said. Why would you want to do this anyways, as you're not actually debugging the application in a state that is representative of how it would run in the "wild"? – David Pine May 27 '16 at 02:21
  • 1
    @DavidPine Thanks. I'm not concerned **at this point** about how it's run in the wild. The logic error is not in the threading, and I'd like to get at the logic error without the additional complexity. – CindyH May 27 '16 at 15:10
  • @CindyH: Your best option then is probably to write a unit test and debug that. – Stephen Cleary May 27 '16 at 15:42
  • @StephenCleary LOL this piece of inherited poo is so far away from PROPER unit testing... But maybe I could write a highly improper unit test to go with the highly improper code - thanks. Currently, I'm just trying to get it to run in dev because it was written against prod, with static variables and home-grown if-then-else statements (really!) and hardcoding. And the sad thing is that it's less than a year old (developer no longer works here, fortunately). – CindyH May 27 '16 at 17:14
  • The problem described (debugger steps through lines out of order) is likely caused not by multithreading but by compiler optimizations. To disable optimization, [How can I disable compiler optimization in C#?](https://stackoverflow.com/questions/1199204/how-can-i-disable-compiler-optimization-in-c) – user2084572 Nov 17 '17 at 17:04

0 Answers0