简体   繁体   中英

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. There is no error message and the UI of the application is still running fine. It just stops processing data.

Specifically for this case I added a simple website for myself where the Backgroundworker reports the current DateTime. So when the DateTime on the website is somewhat current I know it is running fine. 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.

Now for debugging: Is there a way in Visual Studio that I can see where the application currently is? 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.

2.- log files. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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