You need some kind of interface to capture keystrokes.
Here is an example that runs in a console application (create empty and paste defauklt into the module)
It allows you to handle "SOMETHING" in the background thread, leaving the GUI inactive for user input to commands. In this case, just a simple 1 second delay counter 1000.
Option Compare Text
Module Module1 Sub Main() Console.WriteLine("Enter ""Start"", ""Stop"", or ""Exit"".") Do Dim Com As String = Console.ReadLine Select Case Com Case "Start" Console.WriteLine(StartWork) Case "Stop" Console.WriteLine(StopWork) Case "Exit" Console.WriteLine("Quiting on completion") Exit Do Case Else Console.WriteLine("bad command Enter ""Start"", ""Stop"", or ""Exit"".") End Select Loop End Sub Public Function StartWork() As String If ThWork Is Nothing Then ThWork = New Threading.Thread(AddressOf Thread_Work) ThWork.IsBackground = False 'prevents killing the work if the user closes the window. CancelWork = False ThWork.Start() Return "Started Work" Else Return "Work Already Processing" End If End Function Public Function StopWork() As String CancelWork = True If ThWork Is Nothing Then Return "Work not currently running" Else Return "Sent Stop Request" End If End Function Public CancelWork As Boolean = False Public ThWork As Threading.Thread = Nothing Public dummyCounter As Integer = 0 Public Sub Thread_Work() Try Do dummyCounter += 1 Console.Title = "Working ...
source share