2

Does anyone know how to programmatically ignore a thread while debugging?

I understand that threads can be flagged or filtered in the thread window but I would like to automate this so that I don't have to continuously ignore new incoming traffic from sources like SignalR.

Something like

if (myCondition && System.Diagnostics.Debugger.IsAttached)
    System.Threading.Thread.CurrentThread.IgnoreDebugger();

EDIT: Addition Constraints

I would like to ignore the identified thread as well as any child threads generated through Async behavior. Maintaining a collection of threads to ignore or allow would require me to add the same filter/filter helper on all future breakpoints, so I'm hoping for a thread flag or debugger level item instead of a per-breakpoint solution

Steve
  • 1,995
  • 2
  • 16
  • 25
  • I've used conditional breakpoints for this sort of thing. Though that isn't exactly what you're asking, would that be an acceptable solution? See https://stackoverflow.com/questions/5304752/how-to-debug-a-single-thread-in-visual-studio –  Nov 09 '18 at 18:28
  • what condition are you using, my goal is to not update the threadId filter every time I need to debug. – Steve Nov 09 '18 at 18:37
  • I pick a thread, get its ID, and check the current thread's ID against that value in the breakpoint's filter. It changes everytime you start the application, but doesn't require code changes which might accidentally make it into a release. –  Nov 09 '18 at 18:39
  • What does your `myCondition` look like? Any thread that originates from SignalR? –  Nov 09 '18 at 18:41
  • Can be anything which is why I left it generic, but in my case it would be a URL pattern to determine if the incoming request is signlar traffic – Steve Nov 09 '18 at 18:45
  • Never done this before. Is this as simple as a conditional breakpoint? Can’t you have the application look up its thread id and put it in a variable. And then in VS have the filter (conditional breakpoint?) filter by the variable as id? – nl-x Nov 09 '18 at 18:54
  • I would look at that thread's stack trace. If it contains "SignalR", you have a winner. It would likely be slow though. You might also be able to check for the existence of certain variables on the AppDomain, or look in the logical call context for certain values. I'm not sure what those variables or values might be, though. If the current thread has an OwinContext, you can check it for SignalR. –  Nov 09 '18 at 19:02
  • I would like to ignore the identified thread as well as any child threads generated through Async behavior. Maintaining a collection of threads to ignore or allow would require me to add the same filter/filter helper on all future breakpoints, so I'm hoping for a thread flag or debugger level item instead of a per-breakpoint solution – Steve Nov 09 '18 at 19:07

0 Answers0