I have written a few C# apps that I have running via windows task scheduler. They are running successfully (as I can see from the log files that they are writing ) but windows task scheduler shows them returning a last run result of 0xE0434352
. Is there something I need to do in my C# application so that it returns a success code to the windows task scheduler?
我已经编写了一些通过windows任务调度器运行的c#应用程序。它们正在成功地运行(从它们正在编写的日志文件中可以看到),但是windows任务调度程序显示它们返回0xE0434352的最后运行结果。在我的c#应用程序中是否有什么事情需要做,以便它返回到windows任务调度程序的成功代码?
8 个解决方案
#1
59
Another option is to simply use the Application log accessible via the Windows Event Viewer. The .Net error will be recorded to the Application log.
另一种选择是使用可通过Windows事件查看器访问的应用程序日志。. net错误将被记录到应用程序日志中。
#2
26
When setup a job in new windows you have two fields "program/script" and "Start in(Optional)". Put program name in first and program location in second. If you will not do that and your program start not in directory with exe, it will not find files that are located in it.
在新的windows中设置作业时,您有两个字段“程序/脚本”和“开始(可选)”。将程序名放在第一个,程序位置在第二个位置。如果您不这样做,并且您的程序开始时不在exe目录中,那么它将不会找到位于其中的文件。
#3
22
Hans Passant was correct, I added a handler for AppDomain.CurrentDomain.UnhandledException as described here http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71).aspx I was able to find the exception that was occurring and corrected it.
Hans Passant是正确的,我添加了一个AppDomain.CurrentDomain的处理程序。这里描述的UnhandledException: http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71)。
#4
10
I was referencing a mapped drive and I found that the mapped drives are not always available to the user account that is running the scheduled task so I used \\IPADDRESS
instead of MAPDRIVELETTER:
and I am up and running.
我引用了一个映射驱动器,发现正在运行计划任务的用户帐户并不总是可以使用映射驱动器,所以我使用了\IPADDRESS而不是MAPDRIVELETTER:我已经启动并运行了。
#5
6
In case it helps others, I got this error when the service the task was running at didn't have write permission to the executable location. It was attempting to write a log file there.
如果它可以帮助其他人,我在任务运行的服务没有对可执行位置的写权限时得到了这个错误。它试图在那里写一个日志文件。
#6
2
I had this issue and it was due to the .Net framework version. I had upgraded the build to framework 4.0 but this seemed to affect some comms dlls the application was using. I rolled back to framework 3.5 and it worked fine.
我有这个问题,这是由于。net框架版本。我已经将构建升级到框架4.0,但这似乎影响了应用程序正在使用的一些逗号。我回滚到框架3.5,它工作得很好。
#7
1
I got the same error but I have fixed it by changing the file reading path from "ConfigFile.xml" to AppDomain.CurrentDomain.BaseDirectory.ToString() + "ConfigFile.xml"
我得到了相同的错误,但我通过改变“ConfigFile”的文件读取路径来修复它。xml" to AppDomain.CurrentDomain.BaseDirectory.ToString() + " config .xml"
In my case, this error due to file path error because task manager starts program from "System32" as initial path but the folder we thought.
在我的例子中,这个错误是由于文件路径错误,因为任务管理器从“System32”启动程序作为初始路径,而不是我们认为的文件夹。
#8
-3
If you use "My.MySettings.Default" maybe, you need to change the user who run that application
如果你使用“My.MySettings。默认“也许,您需要更改运行该应用程序的用户
#1
59
Another option is to simply use the Application log accessible via the Windows Event Viewer. The .Net error will be recorded to the Application log.
另一种选择是使用可通过Windows事件查看器访问的应用程序日志。. net错误将被记录到应用程序日志中。
#2
26
When setup a job in new windows you have two fields "program/script" and "Start in(Optional)". Put program name in first and program location in second. If you will not do that and your program start not in directory with exe, it will not find files that are located in it.
在新的windows中设置作业时,您有两个字段“程序/脚本”和“开始(可选)”。将程序名放在第一个,程序位置在第二个位置。如果您不这样做,并且您的程序开始时不在exe目录中,那么它将不会找到位于其中的文件。
#3
22
Hans Passant was correct, I added a handler for AppDomain.CurrentDomain.UnhandledException as described here http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71).aspx I was able to find the exception that was occurring and corrected it.
Hans Passant是正确的,我添加了一个AppDomain.CurrentDomain的处理程序。这里描述的UnhandledException: http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71)。
#4
10
I was referencing a mapped drive and I found that the mapped drives are not always available to the user account that is running the scheduled task so I used \\IPADDRESS
instead of MAPDRIVELETTER:
and I am up and running.
我引用了一个映射驱动器,发现正在运行计划任务的用户帐户并不总是可以使用映射驱动器,所以我使用了\IPADDRESS而不是MAPDRIVELETTER:我已经启动并运行了。
#5
6
In case it helps others, I got this error when the service the task was running at didn't have write permission to the executable location. It was attempting to write a log file there.
如果它可以帮助其他人,我在任务运行的服务没有对可执行位置的写权限时得到了这个错误。它试图在那里写一个日志文件。
#6
2
I had this issue and it was due to the .Net framework version. I had upgraded the build to framework 4.0 but this seemed to affect some comms dlls the application was using. I rolled back to framework 3.5 and it worked fine.
我有这个问题,这是由于。net框架版本。我已经将构建升级到框架4.0,但这似乎影响了应用程序正在使用的一些逗号。我回滚到框架3.5,它工作得很好。
#7
1
I got the same error but I have fixed it by changing the file reading path from "ConfigFile.xml" to AppDomain.CurrentDomain.BaseDirectory.ToString() + "ConfigFile.xml"
我得到了相同的错误,但我通过改变“ConfigFile”的文件读取路径来修复它。xml" to AppDomain.CurrentDomain.BaseDirectory.ToString() + " config .xml"
In my case, this error due to file path error because task manager starts program from "System32" as initial path but the folder we thought.
在我的例子中,这个错误是由于文件路径错误,因为任务管理器从“System32”启动程序作为初始路径,而不是我们认为的文件夹。
#8
-3
If you use "My.MySettings.Default" maybe, you need to change the user who run that application
如果你使用“My.MySettings。默认“也许,您需要更改运行该应用程序的用户