whileループ中にコードを実行するビジュアルベーシックのコンソールアプリケーションで作業しています。エスケープキーが押された場合は、whileループをすぐに終了したいと思います。Visual Basic 2012:すぐにループ中に終了する
100万のチェックポイントを置かなくても、エスケープキーを連続して聞くことができます。私は、以下の例(サンプルのために書いたもの)で、 "readline"チェックの間に値を変更する機会があることを認識しています。 ご協力いただければ幸いです!
Dim inp As Char
Dim x, y, z As Integer
While inp <> Chr(27)
console.writeline ("Press escape at any time to exit")
console.writeline ("Please enter a numeric value: ")
x = console.readline()
If x > 1 Then
console.writeline ("greater")
Else
console.writeline ("lesser")
End If
console.writeline ("Do you have other values? Y or N")
inp = console.readline()
If inp = "y" Then
'...other stuff
Else
console.writeline ("Press escape to exit or any other key to continue")
inp = console.readline()
End If
End While
これは同様の質問です:http://stackoverflow.com/questions/5891538/listen-for-key-press-in-net-console-app あなたがしようとしていることに基づいて、別のスレッドのループが私にとって最も理にかなっています。その後、キーの状態をポーリングし、必要なときに終了することができます。 –
フィードバックをいただきありがとうございます。この情報に基づいて、マルチスレッドが最善の方法です。 – Kolo39