none
C# Console App - Task Scheduler - How to Debug?

    Question

  • Hello

    I have a C# console app which is scheduled using Task Scheduler.

    I would like to debug the application when it is fired through the scheduler.

    I have added a code "System.Diagnostics.Debugger.Break();" in my Main function but still it doesn't hit the point.

    Can anyone help me how do we do this please?

    Thanks

    Bab

    Wednesday, May 3, 2017 1:08 PM

Answers

  • One thing to try which I do when debugging a Windows Service is to place the following line at the point you want to debug.

    Debugger.Launch();

    This will cause Visual Studio to prompt to attach to the (in my case) service and you then can debug from there. If you start your project first then you need to attach to new instance of VS, if the project was started outside VS then you can use the current open VS.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Bab LD Wednesday, May 3, 2017 2:22 PM
    Wednesday, May 3, 2017 1:49 PM
    Moderator

All replies

  • One thing to try which I do when debugging a Windows Service is to place the following line at the point you want to debug.

    Debugger.Launch();

    This will cause Visual Studio to prompt to attach to the (in my case) service and you then can debug from there. If you start your project first then you need to attach to new instance of VS, if the project was started outside VS then you can use the current open VS.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Bab LD Wednesday, May 3, 2017 2:22 PM
    Wednesday, May 3, 2017 1:49 PM
    Moderator
  • Hi Karen

    Many thanks for your reply.

    I have used Debugger.Launch() in windows services before and it has worked, I didn't try the same in this scenario before posting the question. 

    This has worked now :) 

    Thanks a lot for the quick help.

    Regards

    Bab

    Wednesday, May 3, 2017 2:22 PM