Page 1 of 1
Attached Debugger not working

Posted:
Fri Sep 09, 2022 5:36 am
by sameermoin
Hi,
I am working on a plugin to debug the issue. I am attaching the debugger using System.Diagnostics.Debugger.Launch(); but it's not working for me. Sometimes it triggers only on the first run of the scheduler service when it starts and after that, it stops working. I tried removing the existing database and recreating it. Even though I also reinstalled the visual studio, this is also not working.
I am using Visual Studio 2022 Enterprise edition.
Thanks
Re: Attached Debugger not working

Posted:
Fri Sep 09, 2022 10:44 am
by Mike.Sheen
sameermoin wrote:I am working on a plugin to debug the issue. I am attaching the debugger using System.Diagnostics.Debugger.Launch(); but it's not working for me. Sometimes it triggers only on the first run of the scheduler service when it starts and after that, it stops working.
So it does work, just not all the time?
Try adding
- Code: Select all
System.Diagnostics.Debugger.Break();
AFTER your line
- Code: Select all
System.Diagnostics.Debugger.Launch();
Re: Attached Debugger not working

Posted:
Fri Sep 09, 2022 1:14 pm
by SBarnes
One problem that can cause this is it depends who is logged onto the machine at the time, for example if there is another active user with Administration privileges quite often it can launch for the other user, one way around this is change the windows account the service is running under to the logged in user.
Like Mike also suggested use launch and break in tandem.
Re: Attached Debugger not working

Posted:
Fri Sep 09, 2022 4:11 pm
by sameermoin
Yes, it worked only for one time. Suppose I have a scheduler that runs every 10 mins named "something".
I have an if condition in the scheduler service Execute method.
if(Schedule.Name == "something"){
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
// more lines of code
}
In this case, the scheduler will run only if I stop the scheduler service and start it again after that when the scheduler started it will execute the below lines and does not stop the execution.
Regarding users. I am not in a domain environment and there is only one user on my machine.
Re: Attached Debugger not working 

Posted:
Fri Sep 09, 2022 7:26 pm
by Mike.Sheen
sameermoin wrote:I have an if condition in the scheduler service Execute method.
if(Schedule.Name == "something"){
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
// more lines of code
}
In this case, the scheduler will run only if I stop the scheduler service and start it again after that when the scheduler started it will execute the below lines and does not stop the execution.
The first time it does break, in Visual Studio put a breakpoint in the code - even on the lines System.Diagnostics.Debugger.Launch(); or System.Diagnostics.Debugger.Break(); would be fine. Leave Visual Studio open, and you'll be able to debug after the first execution.