从Windows启动的应用程序触发错误C#

编程入门 行业动态 更新时间:2024-10-28 01:17:35
本文介绍了从Windows启动的应用程序触发错误C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

美好的一天, 我有一个以Windows开头的C#应用​​程序。应用程序启动的那一刻,它会立即检查数据库中是否有任何数据。当应用程序正常启动时,一切正常,但是当我重新启动并允许它启动Windows时,它会让我程序已停止工作错误。我检查了偶数日志,似乎应用程序在SQL Server启动之前尝试连接到数据库。如何克服这个问题? 就像我说的那样。在它给我错误之后,我只需双击桌面上的图标即可完美启动。因此,当应用程序尝试使用Windows启动时,问题必然是SQL Server无法正常运行。 我尝试过: b $ b 我不知道该怎么回事。我有一点谷歌搜索,但似乎我是唯一有这个问题的人。

Good day, I have a C# application that starts with windows. The moment the application starts it immediately does checks on the database for any data. When the application is started normally everything works, but when I restart and allow it to start up with windows, it gives me "Program has stopped working" error. I Checked the even logs and it seems like the application is trying to connect to the database before SQL Server is started. How can this issue be overcome? Like I said. After it gives me the error, I can simply double click the icon on the desktop and it starts perfectly. So the issue has to be with SQL Server not running properly when the application tries to start with windows. What I have tried: I have no idea what to try unfortunately. I have googled a bit, but seems like I am the only one with this problem.

推荐答案

用这个检查SQL Server是否正在运行 [ ^ ] 使用计时器 [ ^ ]每隔30秒或1分钟检查一次连接一旦建立连接,它就会连接起来,然后在经过的事件中停止计时器。 Use this to check the SQL Server is Running or not [^] use Timer[^] to check the connection for every 30 seconds or 1 minute till it gets connected, once the connection is established then stop the timer in the elapsed event.

好的,既然你同意这个,我会在这里用一些代码扩展评论。这就是我想象那里的东西。 Ok, since you agreed with this, I'll extend the comment with some code here. This is how I imagined the stuff there. static void connectToDB() { // considering that the connection always throws an Exception throw new Exception("DB is down"); } static void Main(string[] args) { bool connected = false; while (!connected) { try { connectToDB(); connected = true; } catch (Exception ex) { System.Threading.Thread.Sleep(1000); } } }

看看是否有帮助;如果没有,我们可能需要更多信息。

See if it helps; if not, we might need some more information.

更多推荐

从Windows启动的应用程序触发错误C#

本文发布于:2023-11-02 13:11:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552495.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   错误   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!