Debugging program freeze on another machine - c#

I have an application that is exhibiting strange behavior that I'm having trouble figuring out. It works fine on my machine and many user machines. However on some machines, seemingly at random, it just hangs. I was able to get on a support online meeting with a user and run a trace on their system while it was stalled. Here is a trace screen shot:
It appears that for 29.6 out of 30 seconds some threads were waiting on each other to complete, and were called almost 6,000 times. I've been trying to google this and have looked plenty here as well and from what I gather this suggests a thread deadlock condition. The problem is that this application only uses background threads in a few locations and this constructor shouldn't be one of them as far as I'm aware. Here is the code for the constrcutor:
InitializeComponent();
if (KMApplication.Settings != null)
{
_useWin10 = KMApplication.Settings.ForceSpellingMode == SpellChecker.SpellingModes.Windows10
|| (KMApplication.Settings.ForceSpellingMode == SpellChecker.SpellingModes.Automatic && Utility.IsWindows10());
}
The XAML for this control is pretty lengthy but I can copy it if necessary...
So my question is if anyone can tell from that what is going on, or if not what is the best way to go about looking for the issue here?

Ok so after a ridiculous amount of debugging and testing I figured out that this is not related to threading at all. It actually was related to spell checking of all things. It ended up being the issue shown in this question. If you look at the answer by am7zd they describe exactly what the issue ended up being. Not sure why it shows up this way in the trace but it's misleading, it's actually registering a bunch of dictionaries in all the text boxes and taking forever to create them. In the case of this user there were like 1800 non-existent files in that setting and once I cleared them up everything went back to normal speed.
Hopefully that helps someone running into similar issues...

Related

Getting the error "Session [(null externalkey)] not available and is not among the last 1000 terminated sessions." when running on Selenium Grid

Alright, so there are many similar questions to this one however I have exhausted all options that I have seen. I am hoping that someone will have more information to share.
The Details
I run five instances of test at a time, using Nunit (v3.10.1) on Chromedriver (v2.41) in the Selenium Grid (v3.14). I only get this error when running tests on the grid, this does not happen running locally. I typically use the default configuration for both the Selenium-Hub and the Selenium-Node.
What I Have Tried
I have spent quite some time researching this issue to find a solution to my problem, I have gotten a few results that had seemed promising but have not seemed to have had any effect.
Increasing the Timeout/browserTimeout in the hub/node config
Running 1 session at a time instead of 5
Separating the tests onto different nodes on the same hub
Adding the '--no-sandbox' property to Chromedriver
Increasing wait times within my framework to give the driver more time to start up
I have also tried catching the WebDriverException, but it seems to be uncatchable sometimes.
Reverting to older versions of Selenium-Grid/Chromedriver
Let me know if there is any more information needed. I'm hoping that someone has some helpful information for this topic.
In my curiosity, I've noticed something I hadn't before. When I go to the Selenium-hub, more specifically to hubaddress/wd/hub/sessions I see the following as a result:
As a driver closes and a new one opens, the Active Sessions [ext key ...] changes. So it seems that this exception always exists, and individual instances are not triggering it. (I think) Is it possible that NUnit cannot determine the reason for test failure and instead displays this exception?

C# Application crashing upon closing custom form

I have went through different questions and didn't really find anything that suited my problem, but I also didn't exactly know what to look up to get any results either, so I may have missed some entries. If anyone could link to something that might be of assistance, I would greatly appreciate it.
I'll start off by posting a code example that I'm using (Is not the exact code, as I cannot release this) that I think is causing the application to crash.
using (var editForm = new frmEditableText("Alarm Note", "Title"))
{
var result = editForm.ShowDialog(this);
if (result == DialogResult.OK)
{
string temp = editForm.ReturnValue;
string xPath = String.Format("AlarmsDb/Alarm[Id = '{0}']/Notes", alarmID);
if (!Tools.OverWriteXMLSingleNote(alarm_xml_path, xPath, temp))
logErr("Error overwiting XML alarm: {0}", xPath);
AlarmDb.SetNote(alarmID, temp);
}
}
Tools is a private codebase that houses miscellaneous universal tools that get ported from project to project.
I'm not exactly sure what is going on. I know this code works as it is working on all other code lines I have used it in.
The only thing that is different is the PC itself.
The way it's setup is in a datagridview, on cell click it pops up a form for you to put your notes for that specific row and save them.
Once the form pops up, I close it and immediately the app crashes and won't recover, but there is no exception being reported either.
This only happens when not running through visual studio (matters not if it's a release or debug build, only if it is or isn't running in visual studio).
I'm sure I may have missed some details, please let me know if there is any other information you need from me, but this about sums up my issue.
EDIT:
With some further debugging, I've added multiple log statements in all places possible that would have to do with the form closing, opening, doing it's intended purpose.
What I've found is the FormClosing event makes it all the way through.
ShowDialog(this) is expected to return a DialogResult enum value, but hangs at the point of which it is actually attempting to return this value causing the application to freeze up.
I've also found that setting thread priority to AboveNormal for the thread which ends up calling the form gets rid of the issue. However I do not think that is a good enough solution.
It appears there was an oversight on my end, although I'm still not certain if this is the correct way to resolve my issue.
I don't have very much knowledge on the whole ApartmentState being MTA or STA, or how to identify when which should be used.
What did solve my issue though was going through all the threads that are spun off my main thread and setting their ApartmentState to STA, which I thought was already done from a previous codeline to resolve another issue I was having (such is the problem with collaboration).
But yes, I went through the entirety of my solution and found all instances of new threads being created and explicitly setting their ApartmentState to STA has resolved the crashing issue.
If anyone can provide some good material defining the differences and when to use either, or how to identify when one should be used over the other, it would be greatly appreciated.
did you try subscribing to the AppDomain.UnhandledException event? You can use this as a final catch all (no pun intended) and log to a file the exception see
https://msdn.microsoft.com/en-gb/library/system.appdomain.unhandledexception(v=vs.110).aspx
Alternatively/additionally - did you look in the event viewer?
Good luck

How to debug an application which suddenly terminates without any feedback?

The application uses Xamarin.Android, which may be a big problem in itself. The problem is that sometimes it just quits (process is being terminated) and there's nothing in the log that can be associated with it. (although I guess that it's related to running out of memory, but I can't yet prove it — according to DDMS, most of the times all is OK, and if Xamarin.Android uses another pool of memory, then I don't know how to measure it)
I've searched the code base for "Environment.Exit" and, of course, didn't found anything.
What are the options for finding the culprit of such thing?
You could try to use the garbage collector by yourself. Just run
Runtime.getRuntime().gc();
The Runtime instance has also a method to read the free memory space. So you could figure out by yourself whether it's a memory problem.
EDIT:
Oh I read that Xamarin uses the C# language. But I'm quite sure that C# has similar methods.
When you say log, are you referring to an application log, or the device log?
When tracking down these sorts of bugs, I've always found aLogCat invaluable.
I open it, clear all the current logs, then use my application up to the point where it crashes. Then I quickly go back to aLogCat, pause it and scroll up to where the error is - it's usually found in the nearest red/orange blocks.
There's a blog post here about how I found attributes left out by the Xamarin linker using this method.

Ways of isolating cause of unresponsive Winforms GUI

I have a large-ish Winforms application written in C# which is periodically unresponsive. The issue seems to occur once the application has been use for an hour or so. Exact timings are difficult to gather as users often go off to work on something selse, get back to it and find it has become unresponsive.
I think a memory leak can be ruled out as I'm not seeing excessive memory usage (I've asked users to send a screenshot of the task manager and memory usagage is the same as I would see when the application is runnning normally)
Similarly, CPU usage is normal (single digit %)
As I've so far been unable to recreate the issue on mydevelopment PC I am planning on sitting next to one of the affected users and mirror every action the user performs in order to recreate this. (I'll be setting up a laptop to RDP in to my main PC)
Recreating the issue is one thing, but I'll need to find out what is actually going on in the application.
Could anyone tell me if running in debug mode (through visual studio) will be sufficient or will I need to do something different?
I've searched through a few posts and I've seen mention of profiling software, however I'm not sure if this would only help with general performance issues or memory management issues.
Alternatively, if anyone has come across similar freezing issues then do you have any suggestions of the kind of causes for this?
Some technical details: Aplication is C#, compiled against .NET 3.5, winforms GUI. There are a few external libraries (most significant is ComponentFactory Krypton Suite). Data access is to a Microsoft SQL Server 2005 database. The solution contains 39 projects, I'm not sure if that might have something to do with it?
Any suggestions/pointers would be greatly appreciated.
The application is working much more reliably now, freezing issues still occur on occasion but nowhere near as often as before.
The issue appears to be related to the endpoint security (in this case, Cisco Security Agent) present in the environment I'm working in, application has been whitelisted and has has significantly rediced the instances of application hangs. The development system I work on does not have this endpoint security present, so it didn't show up in early stages of testing.
Thanks for all your feedback, I think there are still threading and garbage collection issues that need cleaning up, hopefully this should sort out the last few issues.

Find out where a multi-threading C# program is stuck

I have written a C# program having some thousand lines and several threads. Execution works fine for several hours/days until the application, which is running on a Windows server, starts to slow everything (other programs/web server) down as it suddenly begins to use up about 50-80% of the CPU.
I assume that it is stuck in some while-loop, but I do not know where exactly. It would already be a help to know which thread uses up the largest share of the system resources. As there is not any exception thrown, I do not see any direct possibility to find out.
The code has already been inspected but I did not find any significant/obvious programming mistakes.
Does anybody know a good way to let Visual Studio monitor the current CPU-load in order to show where it is used up?
Oh, how I love Managed Stack Explorer. http://mse.codeplex.com/ for most versions of .NET and https://github.com/vadimskipin/MSE for 4.0
Point it at your running application, and it snapshots the stacks of each thread. After looking at a few snapshots, you'll work out where the problem is. Oh, the nastiness of the problem I was facing when I first learnt of this. Oh the joy when it let me find what I'd been hunting for days in just a few minutes.
You can use Perfview (http://www.microsoft.com/en-us/download/details.aspx?id=28567) to capture and the analyse ETL traces when this happens.

Categories