我的 C# 应用程序将 0xE0434352 返回给 Windows 任务计划程序,但它没有崩溃

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14711633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:46:18  来源:igfitidea点击:

My C# application is returning 0xE0434352 to Windows Task Scheduler but it is not crashing

c#.netscheduled-taskstask

提问by Kynrek

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 任务调度程序返回一个成功代码?

回答by Kynrek

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).aspxI 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).aspx我是能够找到正在发生的异常并纠正它。

回答by voidmain

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 错误将记录到应用程序日志中。

You can see these events here:

您可以在此处查看这些事件:

Event Viewer (Local) > Windows Logs > Application

事件查看器(本地)> Windows 日志 > 应用程序

回答by RandyMorris

I was referencing a mapped driveand I found that the mapped drives are not always available to the user account that is running the scheduled task so I used \\IPADDRESSinstead of MAPDRIVELETTER:and I am up and running.

我正在引用一个映射驱动器,我发现映射驱动器并不总是对运行计划任务的用户帐户可用,所以我使用了\\IPADDRESS而不是MAPDRIVELETTER:并且我正在运行。

回答by MDave

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.

如果它可以帮助其他人,当运行任务的服务没有对​​可执行位置的写权限时,我会收到此错误。它试图在那里写一个日志文件。

回答by user3936738

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,但这似乎影响了应用程序正在使用的一些通信 dll。我回滚到框架 3.5,它运行良好。

回答by Dmitry Bosikov

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.

在新窗口中设置作业时,您有两个字段“程序/脚本”和“开始于(可选)”。将程序名称放在第一位,将程序位置放在第二位。如果您不这样做并且您的程序不在带有 exe 的目录中启动,则它将找不到位于其中的文件。

回答by RUTIS

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”更改为AppDomain.CurrentDomain.BaseDirectory.ToString() +“ConfigFile.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”作为初始路径启动程序,但我们认为是文件夹。

回答by Akash Vishwakarma

It is permission issue in my case the task scheduler has a user which doesn't have permission on the server in which the database is present.

在我的情况下,这是权限问题,任务调度程序有一个用户在数据库所在的服务器上没有权限。

回答by MrBritton

I was getting the same message message within dotNet Core 2.2 using MVC 5, however nothing was being logged to the Windows Event Viewer.

我在使用 MVC 5 的 dotNet Core 2.2 中收到了相同的消息消息,但是没有任何内容记录到 Windows 事件查看器中。

I found that I had changed the Project sdk from Microsoft.NET.Sdk.Webto Microsoft.NET.Sdk.Razor(seen within the projects.csprojfile). I changed this back and it worked fine :)

我发现我已将 Project sdk 从 更改Microsoft.NET.Sdk.WebMicrosoft.NET.Sdk.Razor(在projects.csproj文件中看到)。我把它改回来了,效果很好:)