473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3456
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: djozy | last post by:
Please When I press edit button in datagrid then datagrid fields become very large textboxes and my datagrid becomes larger thne before pressing edit button. How can I make them smaller? Thank...
1
by: Gidi | last post by:
i want the enter key press wll be an event this is my eventhandler header this.dataGrid1.KeyPress+=new System.Windows.Forms.KeyPressEventHandler(this.dataGrid1_KeyPress) is it ok and how do i...
0
by: newbie_csharp | last post by:
Hi, I have a grid with a textbox. by default grid is sorted by the first column. by typing in the textbox, grid will be searched. when user click on the second column's header, grid is sorted by...
0
by: Douglas Gage | last post by:
Hi every one I'm building datagrid which needs to have validiation check for each text box. Something will look like this Question Answer 1 abc validiation...
0
by: Slipperman | last post by:
i'm using an EditCommandColumn in a datagrid in order to update the value of a BoundColumn. i'm finding that no matter what attributes i use for the cssclass of the EditItemStyle, i can't control...
0
by: IGotYourDotNet | last post by:
On my page I have to diplays all kinds of data depending on what is selected from the drop down box. What I want to do is have 1 grid to display everything BUT I need the headertext to change and...
2
by: Gaurav Gargate | last post by:
To Group, I am creating a datagrid in an ASP.NET project (C#) at the design time. I will be adding the columns to the datagird at run time. The number of columns, name of the columns, data in...
2
by: Logan | last post by:
i've added a data grid to an aspx form, & i've noticed that the width of the grid is fixed. I want to be able to set the width to fit the entire width of the browser. Such as done in classic...
3
by: alex | last post by:
Hi, can anyone point me to a link whith a sample on how to auto fit the datagrid? i need to 1: each row should occupy as much space as needed, the last row should fill the remaining space (or...
1
by: Kiran | last post by:
Hi, Does any one know how to add a button to every row of a windows form datagird. Can anyone provide me some code on this. I have searched a lot but couldn't find any. I am posting this for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.