I want a RichTextBox to behave like a console window and read a line. This is my first try at threads so it didn't work and skips the method. Should I not use a thread?
bool READING = false;
string READ_str;
public string RL()
{
READ_str = "";
READING = true;
ThreadStart w1 = new ThreadStart(Loop_th);
Thread t1 = new Thread(w1);
t1.Start();
return READ_str;
}
public void Loop_th()
{
while (READING)
{
Debug.WriteLine("READING: " + READING.ToString());
if (!READING)
break;
}
}
private void m_textbox_KeyDown(object sender, KeyEventArgs e)
{
if (READING)
{
string read_ch = e.KeyValue.ToString();
c.w("Read: " + read_ch + ", " + e.KeyCode.ToString());
if (e.KeyCode == Keys.Enter)
{
c.w("Pressed enter");
READING = false;
}
else
{
READ_str += read_ch;
c.w("Readstr: " + READ_str);
}
}
}