Problems with datagrid,dataview getting NullReferenceObject and SEHException

R

- R

Hello all.

I'm new to .Net so please help me out.

I have a application with several "Threads" running to observe various
things. From time to time each thread need to add an log entry, which is
displayed on a form (a datagrid on a form)

there is no database, but i created a dataset using the designer. One
Entity/Table is called Log and contains the log-entries.

The main window opens a OberverHandler class, which opens all the observer-
objects, that contains a timer each (a Threading timer)

Each observer got a reference to ObserverHandler. So when a new log need to
be written, a function on the ObserverHandler is called. This function got
a reference to the dataset through the mainwindow, and it adds the row to
the Log table.

The Log form got a dataView and a ddataGrid. The datagrid.datasource = the
dataview. The dataview opens and makes a = new DataView
(mainWindow.dataset.tables["Log"]) - and is running.

The log-form starts to fill up with the log-entrys, but after a short time
the application fails with a NullReferenceObject or a SEHException.

I tried many different things, including making a local dataTable on the
Log form and add rows to it. All with the same result. No crashes if the
log window is not opened. After it opens there goes from 30 sec's to
several minutes before it crashed.

Any help ?

Is it bad design ?

thanks in advance
- R.

email : rrn at r e sign from dk

--
 
K

Kevin Aubuchon

One change you might consider is for your Observer objects to be invoked as
delegate methods by the observed object. Then you 1) wouldn't need thread
timers, and 2) the delegates could be invoked asynchronously, meaning you
wouldn't have to explicity create threads. The delegates would fire on
threads from the pool, which is managed by the .NET runtime.

It sounds like you have multple threads attempting towrite to on resource
(the datagrid). The access to the datagrid should be synchronized. Also,
only the GUI thread can update the datagrid, not your other threads.

kevin aubuchon
 
P

Punjab Peety

- R said:
Hello all.

I'm new to .Net so please help me out.

I have a application with several "Threads" running to observe various
things. From time to time each thread need to add an log entry, which is
displayed on a form (a datagrid on a form)

there is no database, but i created a dataset using the designer. One
Entity/Table is called Log and contains the log-entries.

The main window opens a OberverHandler class, which opens all the
observer- objects, that contains a timer each (a Threading timer)

Each observer got a reference to ObserverHandler. So when a new log need
to be written, a function on the ObserverHandler is called. This function
got a reference to the dataset through the mainwindow, and it adds the row
to the Log table.

The Log form got a dataView and a ddataGrid. The datagrid.datasource = the
dataview. The dataview opens and makes a = new DataView
(mainWindow.dataset.tables["Log"]) - and is running.

The log-form starts to fill up with the log-entrys, but after a short time
the application fails with a NullReferenceObject or a SEHException.

I tried many different things, including making a local dataTable on the
Log form and add rows to it. All with the same result. No crashes if the
log window is not opened. After it opens there goes from 30 sec's to
several minutes before it crashed.

Any help ?

Is it bad design ?

thanks in advance
- R.

email : rrn at r e sign from dk

--

Maybe you need a Mutex
 
R

- R

One change you might consider is for your Observer objects to be
invoked as delegate methods by the observed object. Then you 1)
wouldn't need thread timers, and 2) the delegates could be invoked
asynchronously, meaning you wouldn't have to explicity create threads.
The delegates would fire on threads from the pool, which is managed by
the .NET runtime.

It sounds like you have multple threads attempting towrite to on
resource (the datagrid). The access to the datagrid should be
synchronized. Also, only the GUI thread can update the datagrid, not
your other threads.

kevin aubuchon
Just so i'm 100% sure.
I'm currently looking at invoking the ObserverHandler functions from each
Observer object. I'm reading your response as the opposite, namely create
a reference to each ObserverObject from the ObserverHandler (as today),
BUT then let the ObserverHandler trigger the timer event on each
observerObject through invoke methods ??

If this is correct, i have a small problem. Each Observer run at a
different time-delay. Something are just more critical than others.
Can this be achieved with the threadPool ?

Will each Observer not be executed on its own thread, and thereby in
theory still have two ObserverObjects trying to write at the same time ?

And a bonus question - how can one use the whole invoke thing on a normal
class object ? I thought it was related to Components - and i just have a
class (the ObserverHandler) - and cannot find the invoke method on it ?
(I just started looking into threading and invoke, so please be patient
with me)

Thanks for your answars

- R
- R said:
Hello all.

I'm new to .Net so please help me out.

I have a application with several "Threads" running to observe
various things. From time to time each thread need to add an log
entry, which is displayed on a form (a datagrid on a form)

there is no database, but i created a dataset using the designer. One
Entity/Table is called Log and contains the log-entries.

The main window opens a OberverHandler class, which opens all the observer-
objects, that contains a timer each (a Threading timer)

Each observer got a reference to ObserverHandler. So when a new log
need to
be written, a function on the ObserverHandler is called. This
function got a reference to the dataset through the mainwindow, and
it adds the row to the Log table.

The Log form got a dataView and a ddataGrid. The datagrid.datasource
= the dataview. The dataview opens and makes a = new DataView
(mainWindow.dataset.tables["Log"]) - and is running.

The log-form starts to fill up with the log-entrys, but after a short
time the application fails with a NullReferenceObject or a
SEHException.

I tried many different things, including making a local dataTable on
the Log form and add rows to it. All with the same result. No crashes
if the log window is not opened. After it opens there goes from 30
sec's to several minutes before it crashed.

Any help ?

Is it bad design ?

thanks in advance
- R.

email : rrn at r e sign from dk



--
 
R

- R

Maybe you need a Mutex

I tried to insert various lock's (which in my book/mind is somewhat similar
to Mutex).
Now i tested some more and found a strange behaviour:
The form containing the datagrid and dataview (and a local DataTable at the
moment) - i added a button which calls the AddLog method with some dummy-
values.
This works fine.
Then one of the Observer objects inserts into the log, and it displays on
the datagrid. BUT if i try to change any column width or anything i get the
NullReferenceObject thing.
How can this happen after the row has been succesfully inserted into the
datatable ?

thanks for your response btw.

- R.

--
 

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