I am trying to listen on a device and when got a message from that showing it on a datagridview the first but getting the message from the device works perfectly, but the problem is that when I want to set the DGV content I got this exception Cross-thread operation not valid, and I have read this related topic.
but none of them was helpful since there weren't on a binding DGV.
here is my code:
1. first I have a message class which is binded to the DGV,
public class Msg_log
{
public Msg_log()
{
this.Event = null;
this.Operator = null;
}
public string Event { get; set; }
public string Operator { get; set; }
}
and here is how I create another thread in the loadform event:
newThread = new System.Threading.Thread(this.Event_Listener);
newThread.Start();
and in the Event_Listener function
x.Add(message);
MsgDGV.DataSource = null;
MsgDGV.DataSource = x;
MsgDGV.Refresh();
the message object is like this:
Msg_log message = new Msg_log();
and its Event and Operator variables of message have been set correctly, and I put the MSG.DataSource = null, since I want to update my DGV after the new message is comming (Actually this was my idea and if there is any better way for that I would appreciate that) and that's the line I got the exeption:Cross-thread operation not valid. In the other posts I found out that I should use Invoke method but I don't know how to call Msg_DGV.Invoke(??,???); I don't know what should I pass to that to get the right result...
Cheers,