C#-应用程序Windows服务崩溃

问题描述

我有一个Windows Service中内置的C#项目。 它工作正常,但有时会崩溃而无故。

当我检查Windows事件查看器时,我只能看到的是:

Application crash Log

Nom de l’application défaillante <<MyApplicationName>>,version : 7.3.0.0,horodatage : 0x5f4ca7db
Nom du module défaillant : bcryptPrimitives.dll,version : 6.3.9600.18895,horodatage : 0x5a4b0740
Code d’exception : 0xc00000fd
Décalage d’erreur : 0x00001c1d
ID du processus défaillant : 0x1330
Heure de début de l’application défaillante : 0x01d67fc7fd46a198
Chemin d’accès de l’application défaillante : <<MyApplicationPath>>
Chemin d’accès du module défaillant: C:\Windows\SYSTEM32\bcryptPrimitives.dll
ID de rapport : a4242415-ec19-11ea-80ea-00155d0dc716
Nom complet du package défaillant : 
ID de l’application relative au package défaillant : 

我已经检查了异常代码0xc00000fd,它似乎是堆栈溢出错误。但是我找不到它崩溃的地方,也无法以调试模式启动该项目,因为它可能会在3天或一个小时内崩溃。

我尝试过的事情:

            try
            {
                
                ServiceBase[] ServicesToRun;
                Service service = new Service();
                ServicesToRun = new ServiceBase[]
                {
                    service
                };
                if (Process.GetCurrentProcess().ProcessName.Contains("vshost") || RUN_DEBUG)
                {
                    service.Start();
                    while (true) //Code to execute in debug mode,but not the problem
                    {
                        Task.Delay(1000);
                    }
                }
                else
                {                
                    ServicesToRun[0].AutoLog = true;
                    ServiceBase.Run(ServicesToRun);
                }
            }
            catch(Exception ex)
            {
                DateTime now = DateTime.Now;
                string date = now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second;

                string stackTrace = "StackTrace-" + date + ".txt";
                string message = "ExceptionMessage-" + date + ".txt";
                string innerExceptionStackTrace = "InnerStackTrace-" + date + ".txt";
                string innerExceptionMessage = "InnerMessage-" + date + ".txt";

                if (!Directory.Exists("CrashReport-" + date))
                    Directory.CreateDirectory("CrashReport-" + date);
                System.IO.File.Create("CrashReport-" + date + "\\" + stackTrace).Close();
                System.IO.File.Create("CrashReport-" + date + "\\" + message).Close();

                File.AppendAllText("CrashReport-" + date + "\\" + stackTrace,ex.StackTrace);
                File.AppendAllText("CrashReport-" + date + "\\" + message,ex.Message);

                if (ex.InnerException != null)
                {
                    System.IO.File.Create("CrashReport-" + date + "\\" + innerExceptionStackTrace);
                    System.IO.File.Create("CrashReport-" + date + "\\" + innerExceptionMessage);

                    File.AppendAllText("CrashReport-" + date + "\\" + innerExceptionStackTrace,ex.InnerException?.StackTrace);
                    File.AppendAllText("CrashReport-" + date + "\\" + innerExceptionMessage,ex.InnerException?.Message);
                }
                 

                throw ex;
            }

我的目标是在应用程序的最高级别捕获错误。但这没用。

我只是使服务崩溃时自动重新启动,但是我想解决该错误。

谢谢您的帮助,对不起我的英语不好。

更新:

将“尝试捕获”部分移动到服务中。服务再次崩溃,没有报告。

以调试模式执行服务,没有崩溃。 顺便说一句,正常执行的服务在没有任何调用的情况下崩溃了。

每9小时发生一次崩溃。正常堆栈溢出的时间太长。我的代码中没有递归。我在服务代码中唯一遇到的是一个While和一个Thread.Sleep,等待新的治疗

当前使用调试模式下的服务,但不会崩溃。 这是服务问题吗? 在此计算机上运行的其他服务(也是C#)也没有问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...