469,926 Members | 1,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

DataGird-DataSet-Thread problem

Hi, can anyone guide me throught this:

In my application, I have a global DataSet. I then run
FTP processes in up to 10 simultaneous threads and each
thread calls progress events in the main application.
When a progress event is called, the main application
writes the input to the global DataSet. Occasionally,
the DataSet writes itself to an XML file. This all works
fine. - But you can't see what's going on.

To provide a GUI I have a DataGrid on the form and it's
DataSource property is the relevant table in the global
DataSet. This works automatically - as the threads
report back, the data appears on the datagrid.

But, once in a while, the whole application crashes with
this message:

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.

Any ideas?
Nov 15 '05 #1
4 3297
Why don't you debug it and find out exactly what line of code gives you this
exception. That will give you some ideas.

"Eric" <er************@onelan.co.uk> wrote in message
news:05****************************@phx.gbl...
Hi, can anyone guide me throught this:

In my application, I have a global DataSet. I then run
FTP processes in up to 10 simultaneous threads and each
thread calls progress events in the main application.
When a progress event is called, the main application
writes the input to the global DataSet. Occasionally,
the DataSet writes itself to an XML file. This all works
fine. - But you can't see what's going on.

To provide a GUI I have a DataGrid on the form and it's
DataSource property is the relevant table in the global
DataSet. This works automatically - as the threads
report back, the data appears on the datagrid.

But, once in a while, the whole application crashes with
this message:

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.

Any ideas?

Nov 15 '05 #2
Jon
Are your FTP threads using Control.Invoke or Control.BeginInvoke to communicate with the GUI thread?

"Eric" <er************@onelan.co.uk> wrote in message news:05****************************@phx.gbl...
Hi, can anyone guide me throught this:

In my application, I have a global DataSet. I then run
FTP processes in up to 10 simultaneous threads and each
thread calls progress events in the main application.
When a progress event is called, the main application
writes the input to the global DataSet. Occasionally,
the DataSet writes itself to an XML file. This all works
fine. - But you can't see what's going on.

To provide a GUI I have a DataGrid on the form and it's
DataSource property is the relevant table in the global
DataSet. This works automatically - as the threads
report back, the data appears on the datagrid.

But, once in a while, the whole application crashes with
this message:

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.

Any ideas?

Nov 15 '05 #3
Hi - The problem is that the fault is not occuring in my
code - I am not sure how to trap it. It occurs when the
DataGrid is refreshing itself off the DataSet.

if I include the following line in Form_Load, the error
occurs:

dataGridFTP.DataSource=dataSet.Tables["FTP"];

if I comment it out, the error does not occur. It also
only occurs if the DataGrid is visible. But since the
data grid is all there is to my GUI, the user will not be
too pleased.
-----Original Message-----
Why don't you debug it and find out exactly what line of code gives you thisexception. That will give you some ideas.

"Eric" <er************@onelan.co.uk> wrote in message
news:05****************************@phx.gbl...
Hi, can anyone guide me throught this:

In my application, I have a global DataSet. I then run
FTP processes in up to 10 simultaneous threads and each
thread calls progress events in the main application.
When a progress event is called, the main application
writes the input to the global DataSet. Occasionally,
the DataSet writes itself to an XML file. This all works fine. - But you can't see what's going on.

To provide a GUI I have a DataGrid on the form and it's
DataSource property is the relevant table in the global
DataSet. This works automatically - as the threads
report back, the data appears on the datagrid.

But, once in a while, the whole application crashes with this message:

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.

Any ideas?

.

Nov 15 '05 #4
Jon
Calls between threads acting on shared data usually need to be synchronized.
To synchronize with the GUI thread, Control.Invoke is often used.

Try:

private void ThreadFTPProgress(string Status)
{
form1.Invoke(
new LogDelegate( Log ),
new object[]{Thread.CurrentThread.Name, Status} );
}

Your program may have more synchronization problems.
You really need to read up on thread synchronization before using threads.

"Eric" <er************@onelan.co.uk> wrote in message news:06****************************@phx.gbl...
Ummm... sorry, I am a bit out of my depth here, let me
show you code snippets:

public class Form1 : System.Windows.Forms.Form
{
DataSet dsLog=new DataSet("Log");

....

private void InitializeComponent()
{
this.dgUpload = new
System.Windows.Forms.DataGrid();

....

private void Form1_Load(object sender,
System.EventArgs e)
{
dsLog.Tables.Add("Upload");
dsLog.Tables["Upload"].Columns.Add
("File");
dsLog.Tables["Upload"].Columns.Add
("Status");

dgUpload.DataSource=dsLog.Tables
["Upload"];

....
private void RunThreadedFTPs()
{
//The following initiates the threads
string[] row={"","","","",""};
//The following returns the details of
//the next file to upload
row=FilesToFTP.NextDataRow;
Upload up=new Upload();
up.URL=row[0];
up.LocalFile=row[1];
up.RemoteFile=row[2];
up.FTPProgress+=new
Upload.ProgressDelegate(ThreadFTPProgress);
Thread t=new Thread(new ThreadStart
(up.FTPPut));
t.Name=row[1]+"@"+row[0];
t.Start();
}

private void ThreadFTPProgress(string Status)
{
//The following code writes to DataSet
Log(Thread.CurrentThread.Name, Status);
//If the DataGrid is visibile,
//the application may crash

}

.....

public class Upload
{
public delegate void ProgressDelegate(string
Action);
public event ProgressDelegate FTPProgress;

private void ftp1_Progress(object sender,
Dart.PowerTCP.Ftp.FtpProgressEventArgs e)
{
if (e!=null)
{
long FileSize=e.Length;
long Progress=e.Position;
double PercentDone=Convert.ToDouble
(Progress)/Convert.ToDouble(FileSize)*100;
FTPProgress(PercentDone.ToString("##.#"));
}
}

-----Original Message-----
Are your FTP threads using Control.Invoke or

Control.BeginInvoke to communicate with the GUI thread?

"Eric" <er************@onelan.co.uk> wrote in message

news:05****************************@phx.gbl...
Hi, can anyone guide me throught this:

In my application, I have a global DataSet. I then run
FTP processes in up to 10 simultaneous threads and each
thread calls progress events in the main application.
When a progress event is called, the main application
writes the input to the global DataSet. Occasionally,
the DataSet writes itself to an XML file. This all works fine. - But you can't see what's going on.

To provide a GUI I have a DataGrid on the form and it's
DataSource property is the relevant table in the global
DataSet. This works automatically - as the threads
report back, the data appears on the datagrid.

But, once in a while, the whole application crashes with this message:

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.

Any ideas?

.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by djozy | last post: by
reply views Thread by newbie_csharp | last post: by
reply views Thread by Douglas Gage | last post: by
reply views Thread by Slipperman | last post: by
reply views Thread by IGotYourDotNet | last post: by
2 posts views Thread by Gaurav Gargate | last post: by
2 posts views Thread by Logan | last post: by
3 posts views Thread by alex | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.