Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-应用程序Windows服务崩溃_C#_.net_Exception_Service_Stack Overflow - Fatal编程技术网

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

C#-应用程序Windows服务崩溃,c#,.net,exception,service,stack-overflow,C#,.net,Exception,Service,Stack Overflow,我有一个C#内置Windows服务的项目。 它工作正常,但有时会无缘无故地崩溃 当我查看Windows事件查看器时,唯一能看到的是: 我的目标是在应用程序的最高级别捕获错误。但它不起作用 我只是让服务在崩溃时自动重启,但我想解决这个bug 谢谢你的帮助,很抱歉我的英语不好 更新: 将try-catch部分移动到服务中。服务再次崩溃,没有报告 在调试模式下执行服务,没有崩溃。 顺便说一下,正常执行中的服务在没有任何调用的情况下崩溃了 每隔9小时发生一次碰撞。对于正常堆栈溢出来说太长。我的代码中没

我有一个C#内置Windows服务的项目。 它工作正常,但有时会无缘无故地崩溃

当我查看Windows事件查看器时,唯一能看到的是:

我的目标是在应用程序的最高级别捕获错误。但它不起作用

我只是让服务在崩溃时自动重启,但我想解决这个bug

谢谢你的帮助,很抱歉我的英语不好

更新:

将try-catch部分移动到服务中。服务再次崩溃,没有报告

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

每隔9小时发生一次碰撞。对于正常堆栈溢出来说太长。我的代码中没有递归。我在服务代码中得到的唯一东西是
带有
线程。睡眠
等待新的治疗

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

这就是我从该错误中获得的所有详细信息,尝试查找事件查看器中描述的每个文件夹中的每个日志,但绝对没有。请尝试为未处理的应用程序异常添加事件处理程序。您当前拥有的捕获不会在服务线程中看到异常。显示实际服务线程的更多代码,并在其中添加日志记录。是否有任何可疑的处理加密、身份验证、保证调用bcryptPrimitives.dll的行为?我将尝试将try-catch部分移动到服务线程中,如果有消息,我将更新帖子(更新可以是Tomorrow)。我的服务中不使用任何加密。堆栈溢出可能是由嵌套太深的调用(无休止的递归)或太大的局部变量引起的。您可以通过添加检查来检测两者。计算递归深度并监督局部变量的大小。注意非预期的递归。在这种情况下,我的try-catch会报告错误,但我的try-catch不会捕获任何错误。
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 : 
            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;
            }