I'm new to multi-threading
I have two functions I want to run on different threads (if you must know, they are two tcp socket connections to different ports, one acts as a server the other acts as a client)
First: how can i access a text box on the main form? it does not allow me to access non static members, and i cant create a thread on a non static function
Second: how can i push data to the function while it's running?
I may be approaching this the wrong way, anyway this is my code structure (few lines deleted to simplify)
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
Thread lis = new Thread(new ThreadStart(Listen));
Thread con = new Thread(new ThreadStart(Connect));
public Form1()
{
InitializeComponent();
lis.IsBackground = true;
con.IsBackground = true;
}
static void Connect()
{
//try to connect to 127.0.0.1:10500
while (true)
{
//listen and output to Form1.txtControlMessages
//input from Form1.txtCommandToSend and write to the stream
}
}
static void Listen()
{
try
{
//start listen server on port 10502
while (true)
{
//accept client and output to Form1.txtData
}
}
catch (SocketException e)
{
}
}
}