从任务计划程序调试Windows控制台应用程序 [英] Debugging a Windows Console Application from Task Scheduler

查看:67
本文介绍了从任务计划程序调试Windows控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发布此内容之前,我还检查了有关堆栈溢出的先前问题.

I also checked previous questions on Stack Overflow before posting this.

这是我的问题:

我在Visual Studio 2017上创建了Windows控制台应用程序.该应用程序应该从表中获取一些数据并定期发送电子邮件.最初,我创建了Windows服务,并且可以正常运行,但后来我决定从Task Scheduler中执行此服务,因为更改计划很容易.

I created a Windows Console Application on Visual Studio 2017. This application is supposed to fetch some data from tables and send email at regular intervals. Initially, I created a Windows Service and it is working fine but later I decided to execute this from Task Scheduler as changing schedules would be easy.

主要代码如下:

public static void Main(string[] args)
{
   RetrieveData();
}

stativ void RetrieveData()
{
    // Fetch data and send mails
}

有两个问题:

(1)我无法将其附加到进程.首先的问题是,当我以调试模式启动它时,在尝试附加到进程时,应用程序在击中Main时立即退出.

(1) I am not able to attach it to a process. First the issue is that as I start it in debugging mode, the application exits as soon as it hits Main when trying to Attach to process.

(2)当我单击附加到进程"时,.exe名称没有出现在进程名称下.

(2) The .exe name is not appearing under process names when I click "Attach to Process".

从任务计划程序执行该应用程序时,如何调试该应用程序?当Task Scheduler触发此作业时,它甚至没有执行.

How to debug this application when it is executed from a task scheduler? It is not even executing when Task Scheduler triggers this job.

推荐答案

尝试使用 Debugger.Launch().

将此行放在 main 的第一行中,在此项目中将Visual Studio保持打开状态,编译您的项目,安排任务以运行新的已编译可执行文件,然后等待程序询问您打开Visual Studio进行调试.

Put this line in your first line in the main, hold Visual Studio open in this project, compile your project, schedule a task to run your new compiled executable, and wait for your program will ask you to open Visual Studio to debug.

这篇关于从任务计划程序调试Windows控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆