Possible Duplicate:
Updating UI from a different thread
The calling thread cannot access this object because a different thread owns it
Good day to all. I have problem with my chat application, i need to refresh my chat all the time but the error is prompting. I dont know how to fix this issue. i hope someone can help me. here is my code:
void timerChatRefresh_Tick(object sender, EventArgs e)
{
thread = new Thread(new ThreadStart(ChatRefresh));
thread.Start();
}
private void ChatRefresh()
{
conn = new MySqlConnection("Server=...; Database=...; Uid=...; Password=...;");
ds.Clear();
da.SelectCommand = conn.CreateCommand();
da.SelectCommand.CommandText = "select * from chatmessagetbl";
da.SelectCommand.CommandType = CommandType.Text;
da.Fill(ds, "chatmessagetbl");
foreach (DataRow item in ds.Tables["chatmessagetbl"].Rows)
{
textBlockChatArea.Text += item["username"].ToString() + ": " + item["message"].ToString() + "\n";
}
}