cross thread

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
 
C

Cor Ligthert[MVP]

Miha,

Don't use a modern architecture, working with Net is mostly based on the
bahaviour of Internet.

Data on a Server is never at the millisecond actual (if those who do the
input start drinking coffee is is already not actual).

Some pages on Internet are sometimes refressing by a timer, a way you can
use to.

You can use notification, however you will see that your application becomes
dramaticly slow.
http://www.vb-tips.com/default.aspx?ID=97f5073b-4c42-4215-b71c-3503c15fd46e

Cor
 
C

Cor Ligthert[MVP]

Doh,

I did want to write,

Don't use an ancient architecture but go in a more modern way

:)

Cor
 
M

Mihai

A solution that I found is to use Microsoft queue.I will try this anyway.
I think this is "Modern way".
I'm curios Cor , how you can trace activity on each function , subrutine
etc, that reside in a lot of dlls running on the server, or in a web service
to think in a "Modern way". I want something to trace in real time not
writing in a file or database and after that pressing a button to show the
results.
Anyway I will not use this tracing all the time to slow down the server, but
when I used this function I want to see the results on the screen in a
listbox not in a console application.On a console application, my trace
modul works.

Any other ideas will be appreciated !

Regards,
Mihai
 
M

Mihai

I found the answer by myself !
Create first a binding source. Create a datatable where the event insert the
messages.
db.datasource=dt
Bind the datagridview with binding source and voila is working.
is updating in real time.

Regards,
Mihai
 
C

Cor Ligthert[MVP]

Mihai,

Did you not do it like that, confirm your text I was thinking you were doing
this already, there was nothing about this in your text and this is of
course obvious.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top