M
Mihai
Hi to everybody !
I created a class C1 in VB.Net that get some data from a sql server. From a
form F1 I call this class and get this data and show nicely on a
datagridView.
In this class C1 I defined a public shared string variable.
I defined a public event, too.
When for example I read data from sql server i put a value in this shared
string: "get data from server" for example an raise the event.
On another form F2 I created a handler for the event in class C1.When it is
hapening I want to see the message from the shared string in a listbox that
reside on F2.
I execute F2.is ok
when i execute F1 I have this message error:
Cross-thread operation not valid: Control 'lstboxMessages' accessed from a
thread other than the thread it was created on.
When in F2 i set
Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
everything is running OK. But I don't know if is right to use this.
Can someone give me another solution , please ? But with 2 forms.
This is like a resume, because in reality F1 is reside on a computer and
call C1 from the server , F2 is on a server.And all this message I want to
see on the server in real time.
If for example I don't use events, manualy update - pressing a button in F2
is running ok without error.Somehow .net don't like using events in this
mode.
Thank you,
Mihai
I created a class C1 in VB.Net that get some data from a sql server. From a
form F1 I call this class and get this data and show nicely on a
datagridView.
In this class C1 I defined a public shared string variable.
I defined a public event, too.
When for example I read data from sql server i put a value in this shared
string: "get data from server" for example an raise the event.
On another form F2 I created a handler for the event in class C1.When it is
hapening I want to see the message from the shared string in a listbox that
reside on F2.
I execute F2.is ok
when i execute F1 I have this message error:
Cross-thread operation not valid: Control 'lstboxMessages' accessed from a
thread other than the thread it was created on.
When in F2 i set
Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
everything is running OK. But I don't know if is right to use this.
Can someone give me another solution , please ? But with 2 forms.
This is like a resume, because in reality F1 is reside on a computer and
call C1 from the server , F2 is on a server.And all this message I want to
see on the server in real time.
If for example I don't use events, manualy update - pressing a button in F2
is running ok without error.Somehow .net don't like using events in this
mode.
Thank you,
Mihai