473,721 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView.Re fresh() hangs on cross-thread call

Hi all,

I'm having a weird time with a call to the Refresh() method of a
DataGridView. I have a VB.NET 2005 Windows application with a main form and
a "worker" thread. The main form delegates a Sub to the worker so that the
latter can refresh the DataGrid after updating the DataTable driving it.

When I run the app under the debugger, everything's fine. But when I run it
for real, it hangs, apparently in the Refresh() method of the DataGridView -
that is, as soon as I comment out dgRefresh, the hanging goes away.

I'm dealing with the cross-thread issues appropriately, as far as I'm aware:

Public Delegate Sub dgExtRefreshCal lback()
Public Sub dgExtRefresh()
dgExtensions.Re fresh()
End Sub
Private Sub refreshDGExtens ions()
If dgExtensions.In vokeRequired Then
Dim d As New dgExtRefreshCal lback(AddressOf dgExtRefresh)
Me.Invoke(d, New Object() {})
Else
dgExtRefresh()
End If
End Sub

.... so it's "refreshDGExten sions()" that is delegated to the worker
class/thread.

I can't help thinking that there's a timing issue somewhere if it's working
in the debugger but not when run from the desktop. I figured I'd throw some
locking in to ensure that (for instance) the DataTable behind the DataGrid
didn't get updated while the DataGrid was refreshing, but that didn't seem
to help. So any ideas would be most welcome!

Thanks a lot,

David C
Oct 25 '06 #1
3 7586
Hi David,

Based on my understanding, you have WinForms application using multithread.
You refresh the data grid view in a thread other than the application's UI
thread. If the program is started with debugger, every thing works fine.
However, if the program is run from the desktop, it hangs in the Refresh
method of the data grid view. As soon as you comment out the statement of
calling the DataGridView.Re fresh method, the hanging goes away. If I'm off
base, please feel free to correct me.

Firstly, I'd like to say that your dealing with the cross-thread issue is
appropriate. To ensure that access to your controls is done in a
thread-safe way, we should use the Invoke method of the control.

It seems that race conditions or deadlocks occur in your program from the
phenomenon of the program's hanging. For example, you have locked the data
grid view or data table otherwhere and you require the lock on the data
grid view or data table before you refresh the data grid view.

I think the reason why the problem doesn't occur when the program is
started with debugger is that the conditions for race conditions or
deadlocks aren't met when the program is run with debugger.

I suggest that you check the code in your program to find all places where
the data grid view or data table is locked and then correct them.

Please try my suggestion. If the problem isn't solved, you may make a
sample project that could reproduce the problem and send it to me. To get
my actual email address, remove 'online' from my displayed email address.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #2
"Linda Liu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:4c******** ********@TK2MSF TNGXA01.phx.gbl ...

Hi Linda,
Firstly, I'd like to say that your dealing with the cross-thread issue is
appropriate. To ensure that access to your controls is done in a
thread-safe way, we should use the Invoke method of the control.
It seems that race conditions or deadlocks occur in your program from the
phenomenon of the program's hanging. For example, you have locked the data
grid view or data table otherwhere and you require the lock on the data
grid view or data table before you refresh the data grid view.
I think the reason why the problem doesn't occur when the program is
started with debugger is that the conditions for race conditions or
deadlocks aren't met when the program is run with debugger.
Hi Linda,

Yes, that's my suspicion too. Something somewhere is getting deadlocked, but
under the debugger the timing is such that I'm getting away with it - I
figured that I'd double-check that it wasn't a known .NET bug and that I
wasn't doing anything stupid!

I'll keep digging!

All the best,

D.
Oct 26 '06 #3
Hi,

"David Cartwright" <ds**********@c ommunity.nospam wrote in message
news:eb******** ********@TK2MSF TNGP05.phx.gbl. ..
Hi all,

I'm having a weird time with a call to the Refresh() method of a
DataGridView. I have a VB.NET 2005 Windows application with a main form
and a "worker" thread. The main form delegates a Sub to the worker so that
the latter can refresh the DataGrid after updating the DataTable driving
it.

When I run the app under the debugger, everything's fine. But when I run
it for real, it hangs, apparently in the Refresh() method of the
DataGridView - that is, as soon as I comment out dgRefresh, the hanging
goes away.

I'm dealing with the cross-thread issues appropriately, as far as I'm
aware:

Public Delegate Sub dgExtRefreshCal lback()
Public Sub dgExtRefresh()
dgExtensions.Re fresh()
End Sub
Private Sub refreshDGExtens ions()
If dgExtensions.In vokeRequired Then
Dim d As New dgExtRefreshCal lback(AddressOf dgExtRefresh)
Me.Invoke(d, New Object() {})
Else
dgExtRefresh()
End If
End Sub

... so it's "refreshDGExten sions()" that is delegated to the worker
class/thread.

I can't help thinking that there's a timing issue somewhere if it's
working in the debugger but not when run from the desktop. I figured I'd
throw some locking in to ensure that (for instance) the DataTable behind
the DataGrid didn't get updated while the DataGrid was refreshing, but
that didn't seem to help. So any ideas would be most welcome!
Why do you even need to call Refresh ?

If the DataTable is bound to the DataGridView, then you need to use
Control.Invoke to update the DataTable, then the grid will refresh itself.
If you are inserting rows continous then you'll need to set the worker
thread priority to BelowNormal to give the UI thread the chance to update
properly.

In addition you can also batch the inserts (in a temp table) 10 a 50 rows
then merge them with the DataTable bound to the DGV using Control.Invoke.

HTH,
Greetings
Thanks a lot,

David C


Oct 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9691
by: thomasp | last post by:
This is a two part question, 1) The code below should display a form with a datagridview and a few command buttons. This form should allow the user to make change to the records displayed in the datagridview and have to changes written to the Filters table in an MS Access database. The if the user chooses, clicking on the Restore button empties the contents of the Filters table, refills it with the contents of the DefaulFilters...
1
3147
by: RSH | last post by:
Hi, I have a situation where I have a DDL that lists all of the tables in a particular database, and a Datagridview which appears in the same from below the DDL.. When the user selects a new database table from the list I refresh the datagridview with the newly selected tables data. This works fine but after a few tables have been selected it takes a very long time to load some of the tables. Some tables that contain only one row of...
6
50464
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to DataTable. No problem here. However, when I add data (programatically) to the DataTable, the DataGridView does not refresh right away. If I minimize and show my form,
3
1592
by: Meelis | last post by:
Hi Has ´DataGridView row limits? I can't add about 1150 rows from XML file to DataGridView, it just "hangs" Regards; Mex
4
4862
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a sql DataAdapter (da) da.SelectCommand.CommandText = "Select * from Servertbl1" da.Fill(ds, "tbl1") so far, so good. If I add a row to the datagridview I use the following sqlDataAdapter code to update the server table - which works OK when...
1
7781
by: Karl | last post by:
Hi all... This is a good one. You'll like this... I am working on a course management tool that allows certain Courses to be cross referenced with Job Roles and, when they are, whether the course is a priority course or not. Simple. Because there is alot of data stored for each course, I am using a tab control with several pages. The Job Role cross-referencing comes on
2
6997
by: Andrus | last post by:
VSE 2005 .NET 2 WinForms I have DataGridView in virtual mode containing huge number of rows. When user double clicks in column separator line in grid header, application hangs: grid tries to read all rows! How to force DataGridView to resize column only by using visible lines in screen ? I tried
2
5522
by: YouPoP | last post by:
Hi, I have a Window Form to which i added a datagridview. The binding source is working well, but does not update if the database is modified outside the application (i mean not showing the modification made to the database). Trying to solve my problem, i added a timer to the form that Fill the datagridview every xx milliseconds (basically a timer that calls the Form_Load method). The timer is working nicely, but because it always refresh...
5
6683
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to be able to increase or decrease row heights of a populated DataGridView from the keyboard. I set up a test program with menu items to increase and decrease, assigned shortkey keys (ctrl-UpArrow and ctrl-DnArrow), and attached handlers that execute this code: public partial class MainForm : Form { . . . dataGridView.RowTemplate.Height += increment; Refresh();
0
1009
by: enrico via DotNetMonster.com | last post by:
when i click the delete record i want my datagridview to automatically clear the deleted record or refresh my DGV because even though it is already deleted in the database the datagridview doesn't automatically refresh. i want the same on my add record that everytime i will add the datagridview will automatically refresh -- Message posted via http://www.dotnetmonster.com
0
8840
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
9215
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
9131
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
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3189
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
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
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.