Problem with Threading and treeView.
Hello everyone!
ok so I have the following problem:
(look at the buttom for error message)
(check for comments to find whats wrong)
private void connect()
{
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ip = Dns.Resolve("irc.quakenet.org").AddressList[0];
socket.Connect(new IPEndPoint(ip, 6667));
//The problem lays here.////////////////////
////////////////////////////////////////////
this.treeView1.Nodes.Add("Server");
////////////////////////////////////////////
////////////////////////////////////////////
if(socket.Connected)
{
send("NICK " + strNick1);
send("USER " + strNick1 + " 8 " + " * " + ":" + strFirst + " " + strLast);
recive();
}
else
this.richTextBox1.Text += "Could not connect to server";
}
catch(Exception ex)
{
this.richTextBox1.Text += ex.Message + "\n";
}
}
connection() runs from the following lines of code:
Thread thread1 = new Thread(new ThreadStart(connect));
thread1.Start();
The error message says the following:
The action being performed on this control is being called from the wrong thread.
You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action.
I´ve never used Control.Invoke etc before so I would realy appreciate if anyone could help me get this thing working.