473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.NullRef erenceException ' 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 3479
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.NullRef erenceException ' 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.BeginIn voke 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.NullRef erenceException ' 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.Dat aSource=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.NullRef erenceException ' 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 ThreadFTPProgre ss(string Status)
{
form1.Invoke(
new LogDelegate( Log ),
new object[]{Thread.Current Thread.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 InitializeCompo nent()
{
this.dgUpload = new
System.Windows. Forms.DataGrid( );

....

private void Form1_Load(obje ct sender,
System.EventArg s e)
{
dsLog.Tables.Ad d("Upload");
dsLog.Tables["Upload"].Columns.Add
("File");
dsLog.Tables["Upload"].Columns.Add
("Status");

dgUpload.DataSo urce=dsLog.Tabl es
["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=ro w[1];
up.RemoteFile=r ow[2];
up.FTPProgress+ =new
Upload.Progress Delegate(Thread FTPProgress);
Thread t=new Thread(new ThreadStart
(up.FTPPut));
t.Name=row[1]+"@"+row[0];
t.Start();
}

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

}

.....

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

private void ftp1_Progress(o bject sender,
Dart.PowerTCP.F tp.FtpProgressE ventArgs e)
{
if (e!=null)
{
long FileSize=e.Leng th;
long Progress=e.Posi tion;
double PercentDone=Con vert.ToDouble
(Progress)/Convert.ToDoubl e(FileSize)*100 ;
FTPProgress(Per centDone.ToStri ng("##.#"));
}
}

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

Control.BeginIn voke 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.NullRef erenceException ' 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
995
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 you
1
1137
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 write the method, the datagrid doesn't react when i press any key (i tried to debug and i saw that nothing happens when i press any key i read the link that i got from here but it didn't help me to understand how to do it.. thnak yo
0
1142
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 it. then I'd like to search on the second column when user wants to type in the textbox. to do it I need to handle an event which happends when user clicks on the header of a column and change the sort column. I could not find this event. how can...
0
977
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 check 2 345 validiation check 3 def validiation check 4 52 validiation check 5 cgh validiation check
0
885
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 the width of the edit box that appears after clicking the edit button. it always comes out way too wide. i'm aware of TemplateColumn but i don't think that's what i need because it seems to allow you customize the look of a column as it appears...
0
822
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 the data items will change as well. How can I change what data items to display and change the header text based on what is selected in the drop down in code without having to create 100 datagrids on the page? EX: if cars is selected then i...
2
1471
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 the rows etc. will all be decided on the run time. I am using the simple grid.Columns.Add(BoundColumn).... method. BUT I am not able to sort these columns even if the AllowSorting property has been set to true.
2
1180
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 HTML with the table width = 100% Can this be achieved for a data grid? if so how?
3
1127
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 the remaining space should be equally distributed among all colunns). 2: if grid width does not fit summ of actual column widths send add scrollbar.
1
1064
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 the second time. Any help would be appreciated
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.