在 bat 文件中处理应用程序崩溃
我有一个用 C# 编写的应用程序(.NET 控制台应用程序),在服务器上运行。有时(大约每周两次)应用程序崩溃,这可能是由于网络故障或类似原因引起的,但这并不重要,但是我想要的是,当应用程序崩溃时我想要它只是默默地重新启动。我无法重写应用程序来执行此操作,因为我没有源代码,并且我想要一个简单的解决方案,因此我尝试创建一个如下的 bat 文件:
:start
@BotR.TestR.exe
echo sleeping
@ping 123.45.67.89 -n 1 -w %1000 > nul
goto start
但是,每当应用程序 (BotR.TestR. exe)崩溃时,它会弹出一个弹出窗口,告诉您应用程序崩溃了,它会阻止它继续运行,从而阻止它重新启动。有什么简单的方法可以解决这个问题吗?
I have a application (.NET console app) written in C# that I run on a server. From time to time (about 2 times a week) the application crashes, this might for instance be caused by the network going down or something like that, but that's not important, what I want however, is that when the application crash I want it to simply silently restart. I can't rewrite the application to do this as I don't have the source, and I would like a simple solution to this, so I tried to create a bat file like this:
:start
@BotR.TestR.exe
echo sleeping
@ping 123.45.67.89 -n 1 -w %1000 > nul
goto start
However, whenever the application (BotR.TestR.exe) crashes, it pops up with a popup-window telling that the application crashed, witch stops it from continuing and thus stops it from restarting. Is there any simple way I can solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是最好的方法,但您可以使用 Mono Cecil 重写应用程序像这样做你想做的事:
这段代码的作用是获取应用程序的入口点(通常是
Main()
方法)并将其从这样重写:到这样:
编辑:< /strong>
如果
Main()
方法和包含类是公共的,有一种更简单的方法:创建一个应用程序,将另一个方法作为引用并运行其Main()
。像这样的东西:I'm not sure this is the best way, but you can rewrite the application using Mono Cecil to do what you want like this:
What this code does is to take the entry point of the application (usually the
Main()
method) and rewrite it from this:into this:
EDIT:
If the
Main()
method and the contain class are public, there is an easier way: create an application that has the other one as a reference and runs itsMain()
. Something like this: