1

I have the problem, that my console application wait at random points, until i press the left mouse button. The application is written in C#. I don't use ReadKey or something else in my application (Which even should wait for a key pressed not the mouse).

Does anyone had similar problems?

Thank you!

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • Break execution (with debugger or an external tool like Managed Stack Explorer or CLRStackExplorer. You should be able to see exactly what stops your app – Adriano Repetti Mar 05 '15 at 12:31
  • See http://stackoverflow.com/questions/4453692/windows-console-application-getting-stuck-needs-key-press – xanatos Mar 05 '15 at 12:33

1 Answers1

3

Perhaps you have the Quick Edit mode enabled in your app (Properties->Options->Edit Options). Then if you click the cursor enters in selection mode and the app seems to stop until you click again.

I've made some checks... It seems that if you enter in Quick Edit mode (and you don't exit it), the next time the program will do a Console.Write or similar the program will be "suspended". Clearly programs that don't write anything to output are immune to this problem.

So:

for (int i = 0; ; i++) { }

Immune to Quick Edit.

while

for (int i = 0; ; i++) { Console.Write(i); }

Not immune :-)

xanatos
  • 109,618
  • 12
  • 197
  • 280
  • Oh, thank you, but it not only *seems* to stop, it really stops or am i wrong? – BendEg Mar 05 '15 at 12:33
  • @BendEg Complex to measure :-) Wait a minute :-) – xanatos Mar 05 '15 at 12:36
  • 1
    @BendEg I'll say that it suspends the next write to the Console. What does it means? `while(true) { i++; }` won't be suspended and will continue adding 1, while `while(true) { Console.Write(i++); }` will stop. Reads seems to be non-blocking – xanatos Mar 05 '15 at 12:40
  • Thank you, that was some thing i did not know about `Console.WriteLine`. Woul you like to add this to your answer? :) – BendEg Mar 05 '15 at 12:46
  • @BendEg Done. Added the results of the tests I've done – xanatos Mar 05 '15 at 12:49