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

DataGird-DataSet-Thread problem

P: n/a
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
Share this Question
Share on Google+
4 Replies


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

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

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

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