The program '[12460] TestProject.exe' has exited with code -1 (0xffffffff) - c#

I am writing a c# windows form project and when I stop the process this message is shown in the output terminal:
The program '[12460] TestProject.exe' has exited with code -1 (0xffffffff).
Though the app is running correctly, the -1 exit code seems unfamiliar. Please can anyone explain me what -1 exit code means? Could'nt wrap my head around it.

That's the expected behavior. If you click the "Stop" button in Visual Studio, that kills the application immediately and reports the return code as -1 (0xffffffff). If you want to terminate your application normally, click the "X" at the top right corner of the window (if it is a windowed application).
You can also use the "Debug->Detach" menu option to detach the debugger from the application without killing it.

Related

how to exit tcl based command shell programmatically?

I'm running a program in command mode (behind the scene) and output its data to form window. When the I read specific line (i.e., "run failed") I try to close the program using this code:
if (line.Contains("run failed"))
Process[] runProc = Process.GetProcessesByName("abc");
if (runProc .Length == 1)
runProc [0].Kill();
In some computers it works fine, in others I receive: "Access Denied".
I understand it's concerned with the user privileges.
My question is how can I kill the process differently?
The process runs in tcl mode (don't know if it matters) and I see the last line in the form window output is:
abc%
(where abc is the program). Obviously, it shows the command prompt of the program.
If it was running in a command window, I would have typing in the command window:
'quit'
and the program would have ended and terminated.
How can I send a 'quit' to tcl if something went wrong?
The Tcl command to make the current process cease running is exit. By default it exits “successfully” with code 0; use exit 1 (or a larger number, numbers up to 127 are reasonably portable) to use a non-zero exit code indicate a failure.
It might be worthwhile converting the code that you run in the Tcl subprocess into a script so that termination on error happens automatically. It only doesn't do that when you're running interactively.

Console.WriteLine stops execution on Windows 10 until I press enter

I found no solution/answer to this.
private void LogToConsole(EventLog eventLog)
{
var type = TypeToStringOfUniFormLength(eventLog.Type);
Console.WriteLine($"# {type} {eventLog.Message}");
}
This i my "Event-Logger" and i have a very special behaviour. Most of time it's works great. My Console (in console-application) is updated, but sometimes it just stops at the line "Console.Writeline...". The Console is not updated and the execution pauses there. When i click in the console and hit Enter. The Console is updated an the execution continues. There is no specific scenario to reproduce. Is anybody familiar with this error, or even has a solution to this. My next work arround is to just not use a console-app for this.
thank you for your help in advance.
Windows 10 console automatically enters the Mark/Selection mode when you click it(no need to right-click->Mark, like it is with earlier windows consoles).
This is what prevents the application from printing anything, but the application actually continues to work:
The application itself keeps running, but nothing is written to the
screen.
Then
When you exit the selection mode, the process will resume as normal.
If it is not the case, then you will have to debug/dump your application to determine the culprit.

Line by line inspection of code in VS 2012

I have a C# WPF Application code, which I want to understand. I am using f11 and f10 to step-in and step-over. However, once my application begins, I don't know which part of the code is executing.
Here is what I want:
I want to know which part of the code is getting executed even after the application begins and as and when I click on menu in the application, I want to see which part of code is being executed.
Please I am new to c# VS 2012 and WPF. Help me in analyzing the application code.
You have a few options:
Click Pause when running, and then Step Into. This will bring you to the line being called when you click on a button or menu item for example.
Set a break point at the point you want it to break.
Inside your code, place Debugger.Break() to stop the debugger at a specific line of code.
here are some steps you can follow.
Start your debugging from f10 not from F5. this will start you
application under debug mode but from start evetn from main method.
while runing application under debug mode you can use pause button to
peek into where your code is running right now.
Use F11 when you wish to go in to the code(code need to be in your source tree.) to see what calling function is doing.
Use mode Debug while following these steps.

How to see output of a C# console program when running in VS?

I just wrote a clever program called helloworld. It's a C#/.NET 4.5 console app. Deep within the twisted nested mazes of logic there's use of Console.WriteLine().
When I'm running this at a command line, it runs and I see the output. I can do other commands and mess around a bit, and later scroll up to see the output again.
Now I'm in Visual Studio, tweaking the source ("Hi" is more efficient than "Hello") and testing by tapping F5. What happens is a console window pops up and immediately vanishes. I have no idea what the program printed. How can I see the output?
I don't want to modify my source at all. After searching for solutions, I find some who say to use Console.ReadKey() - but then it would suck to be using the program at the command line. There's no real reason the user should have to tap a key when the program has already done its work. Even if i go with this, there's the problem of the output disappearing when the console window closes after a key tap.
I don't want to use Debug.WriteLine() which does write to the output window in VS, but doesn't write ordinary output for the end user to see.
I have discovered ctrl-F5, which runs the program as if it had a final Console.ReadKey() line, but there's still the problem of when I tap any key, all the output vanishes along with the window. Three minutes later, I'm thinking "Oh wait, did it print 'Hello' or 'Helo'?" No way to check.
Seems like the Visual Studio IDE should somehow capture all that a freshly built program writes to its stdout or the Microsoft equivalent thereof, and show it in its "Output" panel, or some panel, for later scrutiny. Maybe it does do this, and I don't yet know the trick to it? Seems like this would be a common desire among millions of C# developers.
If you're working on a .NET Core console application (or .NET Framework via the .NET SDK) using Visual Studio 2019, the behaviour of leaving the console window open after the program has executed will now happen by default:
Specifically:
This should prevent the need to add Console.Read() calls to console apps to prevent the console window from closing immediately after the program has finished executing. The launched console window is also re-used for subsequent runs, so if you’re used to using ctrl+f5, you won’t have lots of console windows to close after you’ve launched your application a few times.
The reason it closes automaticly is because it's done running the program. If you want to see what it did, make it need a new command like hitting any key. The Console.ReadKey(); pauses it and waits for a User to hit a key to continue. Put that command after the commands of instruction you are doing and it will pause it until you hit any key.
Console.ReadKey(); // Pauses until you hit any key
You can also run your program pressing F10 (executes one line by one), with F11 (goes inside a function).
The other option you have is to set breakpoints in Visual Studion and run the program by pressing F5 - it will stop at the next breakpoint. And the breakpoints can have conditions - i.e. conditional breakpoints.
Some options are:
1. wrap #if DEBUG around Console.ReadKey()
2. run directly from an open terminal
3. create a Test project - but again you'll need Console.ReadKey() to stop it closing.

WPF: program.exe doesn't exit "the process cannot access the file.. used by another process"

I've worked on quite a few WPF solutions, and this is the first time i am seeing this problem.
Today it started happening intermittently. where after closing my WPF window, the .exe is still running under visual studio.
so i have to kill my program.exe manually in order to compile again.
Initially i thought because i overrode application start/exit/exception .. but i commented all that out, and it is still happening.
In fact, i see multiple instances of my program.exe in process explorer!
Can't figure out what is causing my exe not to exit. Is there any explicit dipose logic i can add in applicaton exit event to ensure it really exits?
My application consists of single window, and multiple user controls as views.
update
if i open in debug mode. and close the main WPF window, my visual studio does not stop debugging. however call stack window is empty.
You can use the Application.Exit event to log when your application shuts down.
Alternatively, you can attach the debugger to your running instance (even if it wasn't started in the debugger) then pause it to see where it's at. Make sure to look at the Threads tool window, as you may pause outside the UI thread.
This should take care of it, though its probably better to try to figure out the underlying issue.
System.Diagnostics.Process.GetCurrentProcess().Kill();

Categories

Resources