I have written an application on C#, and ported it onto Linux server (RHEL) using Mono and mkbundle. It works fine, but for some reason program is not closing properly. Right now there are over 30 instances of the program running in the background (according to task manager), although the program didn't return any error, and when it is running on windows or even Ubuntu VM it is working properly and closes without problems. What can be the reason? How can I ensure that program stops completely after execution is finished?
Related
We wrote a wpf application using .NET 3.5. We use the CANopen protocal and log4net. The application starts a few tasks all of which are completed. I checked this by writing a message to the log file - everything was ok. Sometimes the application process terminates immediatelly, sommetimes it takes a few seconds and sometimes it does not terminate. Any ideas what could cause this?
I have the simplest C# console app that only does a WriteLine and a ReadLine. For some reason, it doesn't run in standalone mode on the machine it was built. I tried the built executable on another box and it works fine.
Trying to run it on this machine makes it just hang there. It works fine inside VS, just not from the command line.
Trying to attach VS to the hanging process says something along the lines of "ConsoleApplication1 has triggered a breakpoint" but can't see what the problem is (it indicates the breakpoint is _LdrpDoDebuggerBreak#0() in ntdll.dll).
Any ideas on how to diagnose what's going on?
EDIT (answering comments below): Same behavior happens for both Release and Debug. Platform is set to Auto. Both machines tested on are 64-bit. The one it's working on is Windows 7, the one I'm building on (and where it hangs) is Windows 10.
EDIT2: Something else I noticed is that trying to run the app doesn't bring up a console window (so it hangs before that). Also, detaching after attaching to the hanging process also hangs VS.
EDIT3: Here's the full zipped project: (removed). It contains the debug .exe file as well for the curious. It's just a vanilla console application project with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ASD");
Console.ReadLine();
}
}
}
Are you sure that there's nothing in your code except a WriteLine() and a ReadLine()? I haven't tested it, but this sounds like exactly the behavior I would expect from calling Debugger.Break().
The MSDN page has a note:
Starting with .NET Framework 4, the runtime no longer exercises tight control of launching the debugger for the Break method, but instead reports an error to the Windows Error Reporting (WER) subsystem. WER provides many settings to customize the problem reporting experience, so a lot of factors will influence the way WER responds to an error such as operating system version, process, session, user, machine and domain. If you're having unexpected results when calling the Break method, check the WER settings on your machine. For more information on how to customize WER, see WER Settings. If you want to ensure the debugger is launched regardless of the WER settings, be sure to call the Launch method instead.
On the machine where it is working, it's either ignoring this line because you don't have development tools installed, or your settings are such that it just skips it. On the machine you're developing on, the settings would be different. Possibly fees are based on the Windows 7 and 10 defaults, but I don't know.
Finally figured it out. It's my lovely antivirus. Hoping this helps someone in the future, Avast doesn't bring up the usual prompt indicating it's scanning the app or quarantining it or anything. Disabling the shields (Avast Shields Control -> Disable for 10 mins) makes the app work properly. Argh!
Thank you all for the support!
Interestingly the other machine where it works is still running Avast, but I think it's one major version behind. This is for version 10.4.2233.
I'm currently working on a cross-platform app written in C#. I have a huge problem with testing and debugging it under Linux/Mono. When my application hangs due to an error, I have to kill the process (either using stop button in MonoDevelop debugger or using kill(all) command). The problem is, that after killing I cannot start the application again. When restarted from console, it waits a second or two and exits, showing nothing as output. When started from MonoDevelop, debugger loads some assemblies and then the process exits with no error. There seems to be no Mono-related service in process table. The only way to start the application again is to log off and log in again.
What I'm doing wrong?
I have just begun to explore the mono winforms environment and I cannot work out how to start a program from within monodevelop without a console session being started.
My simple program runs okay but when it exits a terminal session is always created & waiting for me to 'press any key'. I guess I could arrange things so that the terminal window closes automatically, but I would rather the app just ran 'natively', is this possible or does the way mono & .net function work preclude it?
As shown in the examples at Zetcode, in 'Main' the rest of the code is started with 'application.run(new aFunction());', I thought this might be the cause of the terminal session occurring but replacing it with:
myNewClass n = new myNewClass();
n.aFunction();
causes the program to not run at all (or maybe just exit without doing anything).
I am an experienced programmer but not familiar at all with C# or the mono/.net environment so 'stating the obvious' may be all that is required in an answer.
MonoDevelop will usually let you start a program with or without it running in an external console.
In MonoDevelop 2.8 on Linux you can control this by context clicking on a project in the solution tree and selecting Options; then Run on external console under the Run section. I'm not sure if you can disable this on OSX.
I have an application (ABC) that I developed and it as a windows application (.exe). It is by itself quite a big application referring a lot of dll's.
However, now there is a requirement that demands that this application(ABC) be a part of an even larger application (XYZ). Hence, I had to change the project type of "ABC" from being a windows application to a class library, and by changing a few lines of code.
My problem is that, ever since I started using ABC as part of XYZ, the application started hanging if I dint perform any operation on it for 10 to 15 mins... I do not have any problems while running it as a separate application.
Any reasons why this might occur?
Any suggestions would be really appreciated...
Thanks,
Ram
Launch XYZ in the debugger. Wait for the app to hang, pause the debugger, and have a look at what each of the threads in your process are busy with.
It might also help to turn on "break on all exceptions"
You can also use remote debugging to debug the application whilst it is running on the user's machine. From your dev machine, you can attach to the process on the user's machine, and then do a debug break to see what the threads are doing.