By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

Problems with datagrid,dataview getting NullReferenceObject and SEHException

P: n/a
- 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

--

Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"- R" <ig****@resign.dk> wrote in message
news:Xn*******************************@63.223.5.24 6...
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

--

Nov 16 '05 #2

P: n/a
- R wrote:
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
Nov 16 '05 #3

P: n/a
- R
"Kevin Aubuchon" <ke************@sbcglobal.net> wrote in
news:BU*******************@newssvr24.news.prodigy. com:
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" <ig****@resign.dk> wrote in message
news:Xn*******************************@63.223.5.24 6...
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

--



--

Nov 16 '05 #4

P: n/a
- R
Punjab Peety <pp****@outsourcers.r.us> wrote in
news:Uv*****************@newsread1.news.pas.earthl ink.net:
- R wrote:
Hello all.

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

REMOVED
--


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.

--

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.