Hi John,
Putting a lock around a variable is the proper way to synchronize access to
the data.
You keep getting a System.NullReferenceException. The exception is always
thrown when there is an attempt to dereference a null object reference. So,
please set a break point on the statement which throws this exception, and
try to see if any variables or parameters are pointing to a null reference,
or any reference are pointing to objects on another thread.
If all is correct, and you still get that exception, please package a small
project which can reproduce this issue and email it to me. I'm always glad
to help. Remove "online" from the email address above is my real email
address.
If anything is unclear, please feel free to reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| From: (e-mail address removed) (John)
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Subject: Re: DataSet connected to DataGrid crashes my app?
| Date: 10 Oct 2003 10:31:25 -0700
| Organization:
http://groups.google.com
| Lines: 114
| Message-ID: <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<#
[email protected]>
| NNTP-Posting-Host: 192.25.240.225
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1065807086 28001 127.0.0.1 (10 Oct 2003
17:31:26 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Fri, 10 Oct 2003 17:31:26 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!newsfeed.freenet.de!fu-berlin.de!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:63383
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Kevin,
|
| Thanks for your posting.
|
| I will study the links you've provided. I read the documentation
| associated with the DataSet and it appears that I only need to
| synchronize writes to the dataset, not reads.
|
| I write to my dataset in only one place. At that place I've put a
| "lock" around the adding of the row:
|
| lock (messages)
| {
| messages.Grant.AddGrantRow(DateTime.Now, id, channel);
| }
|
| However, I still get a crash inside Application.Run(). The crash is:
|
|
| An unhandled exception of type 'System.NullReferenceException'
| occurred in System.windows.forms.dll
| Additional information: Object reference not set to an instance of an
| object.
|
| Is putting a lock around messages the proper way to synchronize access
| to the DataSet?
|
| Thanks,
| John
|
|
| (e-mail address removed) (Kevin Yu [MSFT]) wrote in message
| > Hi John,
| >
| > In a multi-threaded application, you have to do some synchronization on
| > data to prevent two threads access one data at the same time. This
might
| > also cause you application to crash. Here are some articles about
| > synchronizing data:
| >
| >
http://msdn.microsoft.com/msdnmag/issues/03/01/NET/
| >
| >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
| > l/cpconmanagedthreadingsupport.asp
| >
| > If it still doesn't work, I'll be glad to see your code snippet.
| >
| > If anything is unclear, please feel free to reply to the post.
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
| >
| > --------------------
| > | From: (e-mail address removed) (John)
| > | Newsgroups: microsoft.public.dotnet.framework.adonet
| > | Subject: Re: DataSet connected to DataGrid crashes my app?
| > | Date: 9 Oct 2003 09:40:28 -0700
| > | Organization:
http://groups.google.com
| > | Lines: 33
| > | Message-ID: <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > | NNTP-Posting-Host: 192.25.240.225
| > | Content-Type: text/plain; charset=ISO-8859-1
| > | Content-Transfer-Encoding: 8bit
| > | X-Trace: posting.google.com 1065717628 24520 127.0.0.1 (9 Oct 2003
| > 16:40:28 GMT)
| > | X-Complaints-To: (e-mail address removed)
| > | NNTP-Posting-Date: Thu, 9 Oct 2003 16:40:28 +0000 (UTC)
| > | Path:
| >
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
| > m!news.maxwell.syr.edu!postnews1.google.com!not-for-mail
| > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.adonet:63306
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| > |
| > | (e-mail address removed) (Kevin Yu [MSFT]) wrote in message
| > | > | > Hi John,
| > | >
| > | > I'm not quite sure on how this happened. Can you paste a short code
| > snippet
| > | > for me to reproduce the problem? So that I can deliver my
assistance
| > more
| > | > quickly.
| > |
| > | Good idea. I'll see if I can build a small app that demonstrates the
| > | problem.
| > |
| > | > If you are retrieving data asynchronously, the result dataset is in
| > another
| > | > thread. Have you get the result dataset in a proper way?
| > |
| > | I think that this is the problem.
| > |
| > | This is how I add a row:
| > |
| > | messages.Grant.BeginLoadData();
| > | messages.Grant.AddGrantRow(DateTime.Now, id, channel);
| > | messages.Grant.EndLoadData();
| > |
| > | I'm almost certainly calling AddGrantRow() from a thread that did not
| > | create the GUI and did not create the dataset. Is there something
| > | special I have to do (some sort of invoke?) if I'm adding data to a
| > | dataset from another thread?
| > | > Would you also give me some error messages you received? Did you
mean a
| > | > NullReferenceException is thrown in your last post?
| > |
| > | I'll run the app again and let you know.
| > |
| > | Thank you very much for your help!
| > |
| > | John
| > |
|