Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Stop Wait for user input in textbox NOT CONSOLE APP
    primarykey
    data
    text
    <p>I'm writing trying to write a SSH client. Im using the windows forms NOT the console app. I dont want to use it becasue I want to learn how tog et this to work... Anyways onwards to the question. I have a while loop which is running as long as my shell is open. BUT in order to send input via my textbox to the Ssh server I need it to wait for input. I have added an event listener that listens for ENTER KEY. And to fetch then input i have a function which returns the data. Inside that function is a while loop, which is run as long as a variable is true. The whole thing about listing for enter was that i would change the varibale that keept the while inside my function running so that it exited that and returned the data inside the textbox.</p> <p>So I need a way to overide the while loop inside the function and to set the variable to false. I hae heard about override aswell as the threading things but Im not sure on what to do.</p> <p>Here's my code!</p> <pre><code>//Variables public string mHost; SshShell mShell; public string mInput; string pattern = ""; bool mInputHolder = true; //Initiate form! public Form1() { InitializeComponent(); txthost.Text = "sdf.org"; txtuser.Text = "kalle82"; txtpass.Text = "XXXX"; string pattern = "sdf:"; this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(checkforenter); } public void button1_Click(object sender, EventArgs e) { try { mShell = new SshShell(Host, User); mShell.Password = Pass; //WRITING USER MESSAGE txtOutput.AppendText("Connecting..."); mShell.Connect(); txtOutput.AppendText("OK"); //txtOutput.AppendText("Enter a pattern to expect in response [e.g. '#', '$', C:\\\\.*&gt;, etc...]: "); //Stop for user input mShell.ExpectPattern = pattern; mShell.RemoveTerminalEmulationCharacters = true; while (mShell.ShellOpened) { txtOutput.AppendText("\r\n" + "TERMINAL MODE ENGAGED"); txtOutput.AppendText(mShell.Expect( pattern )); string data = userInput(); if (data == "") break; //Data from termninal --&gt; Append to text string output = mShell.Expect(Pattern); txtOutput.AppendText(output); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void checkforenter(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar == (char)13) { mInputHolder = false; } } public string userInput() { while (mInputHolder == true) { } mInputHolder = true; return txtInput.Text; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload