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.
Related
I start a visual studio project with debugging.
The console pops up, and I often accidently highlight something, which causes execution to pause until I unhighlight it ... I don't want it to pause ever unless I've set appropriate breakpoints.
I've tried looking around at the various options, but nothing seemed appropriate.
This superuser response answers the question.
https://superuser.com/questions/1442941/windows-10-console-stops-running-if-i-click-in-the-console-window
Basically a change in behaviour since windows 10 where QuickEdit was enabled by default, so highlighting the console would cause the console to stop printing and pause the program. By disabling QuickEdit it will not longer pause.
In all the demos that Anders or anyone else on Channel 9 does, they have console apps which they run during the demos and those windows stay visible even after the whole of the Main method runs even though they never have a Console.ReadXXX call at the end of their program.
How does that work? I am sure I am being lazy in exploring some Visual Studio configuration option. Do you know what that is?
If you use "Start Without Debugging" (Ctrl-F5), you will automatically get a pause at the end of the application, with a "Press any key to continue . . ." message.
Of course, you will have no debugger attached, so you will not hit any breakpoints.
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.
I've been writing this program for a while now, and I'm finally ready to start testing it. It works 100% on my dev machine, but I wanted to try it on a machine it's never run on. So, I get my program over to a test computer. When I double-click the exe, nothing happened. I opened up task manager, and tried again. I saw the process start, but after about 5 seconds, it disappeared. No errors, no exceptions, no nothing. How would I go about trying to figure out what is going wrong? I'm still fairly new, and I've never had this happen. Thanks for any and all help!
EDIT
Sorry for not mentioning before. This is a winforms application.
EDIT 2
So, turned out what was going on is that I was trying to a dll meant for 64-bit OS into a 32-bit OS. In Windows XP, this threw a BadImageFormatException. However, in Windows 7, as I stated, it threw no exception at all.
This is a pickle, no doubt about it. I've had to debug this type of thing before.
The first bit of useful information is that no exception is being thrown out. This tells me that somewhere in your actual code is the key to solving the problem. You are either trapping an exception and closing silently, or your code is hitting what it considers to be a "normal" exit condition and is closing in what it would consider the normal way.
To figure out where and why it's exiting, I would add debug logging at key points in your application, and attach a listener to the Debug/Trace listener collection that writes out to a file. "Key points" are places where the application is supposed to exit (or the main form of the window is supposed to close), and within any "catch" block or error event handler. Run this new version on the test computer and see what it gives you. That should tell you the basic flow of the program behind the scenes, and through what mechanism it's shutting down.
If you're running a console application, it is possible that it runs and then closes itself.
Trying opening a command prompt, and then executing the application from there.
If your program has output, then you would see it in that command window.
Have you checked the application event log?
Do you have the necessary version(s) of .Net installed?
Perhaps you should put more exception handling with calls to MessageBox.Show("I failed here") through out your application.
I've got an application (that is targetting .Net Framework 2.0) that is running on startup of the System, and I'm trying to get a NotifyIcon to display.
When my program starts up when a user either Runs it normally or is started as a child process after the system has already logged on everything is fine.
If my application starts up as the system is performing an AutoLogon using POSReady2009 (basically XP with Single User set). Then the NotifyIcon never becomes active.
If you subsequently check (in a timer) the .Visible of the Icon at any point later it always reports that it is visible = true.
If you disable the SSDPSrv and restart the Computer, the Icon displays correctly.
I have a sneaking suspicion this is related to .Net 3.5sp1 installed over the top of a .Net 2 system.
Is there some process that I should be following to ensure that my NotifyIcon is always available to the user.
I have setup RegisterWindowMessage("TaskbarCreated") but I don't get this message called, except when you forcilbly Kill Explorer.exe and restart it. Even so, a NotifyIcon interally registers for these notifications anyway, so it shouldn't be required.
I'm happy to stall the startup of my program, but once the program starts up, I expect that the icon shows correctly.
If there is a KB article that I cannot find detailing this I'd be happy with that too.
Hmm... that's odd.
This may not work, and it's possibly not the best way of doing it - but first of all try putting NotifyIcon1.Visible = True in the Load event.
If that isn't working why not try adding this into a timer...
NotifyIcon1.Visible = False
NotifyIcon1.Visible = True
This should then hide and show the icon everytime the timer ticks, at least then you can see if it's working. Maybe only run the timer 10 times and then it ends, that way the script should hide and show the icon 10 times by which time the system should be ready.
Let me know if this works - if not I'll have a scratchy beard moment and have another think!
Well it's kinda dumb but have endedup needing to modify the process of startup to deal with this issue.
Made the program it's own shortcut that get's placed into the Startup folder by our installer.
The program that triggers this no longer starts it automatically. Instead we inform the other program once we have started up (Dropping a trigger file).
The other program then monitors if the user closes us OR we just crash and automatically re-opens the program. [There is a proper process to follow if you wish to fully close down the system]
Inside the startup of the program we check to see if the SSDP service is available and Not set to Disabled.. if so, wait until this service has started. We then check that SQLServer is running.
We then prepare the NotifyIcon and set it's .visible= true and all is good.
Still have kept the RegisterWindowMessage in the event the user somehow kills windows explorer.