简体   繁体   English

我的 C# 应用程序在循环中,如何在代码中找到位置?

[英]My C# application is in a loop, how can i find the position in the code?

I have written a rather large application running in the background, doing dome stuff and processing some data.我写了一个在后台运行的相当大的应用程序,做圆顶的东西并处理一些数据。

Now the problem is, for some time the application runs fine.现在的问题是,有一段时间应用程序运行良好。 But when I check a day later for example the Backgroundworker of my application seems to loop or stuck.但是当我一天后检查时,例如我的应用程序的 Backgroundworker 似乎循环或卡住了。 There is no error message and the UI of the application is still running fine.没有错误消息,应用程序的 UI 仍然运行良好。 It just stops processing data.它只是停止处理数据。

Specifically for this case I added a simple website for myself where the Backgroundworker reports the current DateTime.专门针对这种情况,我为自己添加了一个简单的网站,Backgroundworker 会在其中报告当前的 DateTime。 So when the DateTime on the website is somewhat current I know it is running fine.因此,当网站上的 DateTime 有点最新时,我知道它运行良好。 But when it's in the past I know my application is stuck.但是当它过去时,我知道我的应用程序被卡住了。

The issue comes after a undefined time.问题出现在不确定的时间之后。 It can be 10 minutes or 90 Hours.它可以是 10 分钟或 90 小时。

Now for debugging: Is there a way in Visual Studio that I can see where the application currently is?现在进行调试:是否可以在 Visual Studio 中查看应用程序当前所在的位置? That would make debugging a whole lot easier.这将使调试变得更加容易。 Otherwhise I would have to set breakpoints on trial-and-error base...否则我将不得不在反复试验的基础上设置断点......

Best regards,此致,

Julian朱利安

you have two options:你有两个选择:

1.- attach the debugger as it is suggested already and check the code, but if the application runs fine for a long time, it is not the best idea. 1.- 按照建议的方式附加调试器并检查代码,但如果应用程序长时间运行良好,这不是最好的主意。

2.- log files. 2.- 日志文件。 Create log files to track your application.创建日志文件来跟踪您的应用程序。

What I would do: I would combine both options.我会怎么做:我会结合这两种选择。 Add log files to check results and when the application reached certain points (to decide by you) and then, once I know more or less where the problem is, use the debugger.添加日志文件以检查结果以及应用程序何时达到某些点(由您决定),然后,一旦我或多或少地知道问题出在哪里,请使用调试器。

Good luck祝你好运

Edit:编辑:

I fully concur with this answer but would add that you may benefit from making the background worker pass key position information back to the UI as it enters and leaves particular sections so that you can simply interrogate this when you attach.我完全同意这个答案,但要补充一点,您可能会受益于让后台工作人员在进入和离开特定部分时将关键位置信息传递回 UI,以便您在附加时可以简单地询问它。 Since the problem can take several hours to manifest itself you could end up with a lot of log file to wade through unless you use a rolling log with limited entries, continuously setting a telltale would at least allow you to know approximately where to put the breakpoint at that moment.由于问题可能需要几个小时才能显现出来,除非您使用具有有限条目的滚动日志,否则您最终可能会遇到大量日志文件,连续设置一个告示至少可以让您大致知道将断点放在哪里在那一刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM