473,466 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGridView refresh causes "Not Responding" application (but onlywhen not in Visual Studio)

Ok, extremely wierd situation here:

(I'll post the code below, after the explanation)

I've got a Windows application (.NET 3.5) that has a single Form with
a DataGridView embedded. The user presses a button to do a SQL query
(fill a DataSet). Before firing the query, I disable the grid/buttons
and turn on UseWaitCursor. After it completes, I re-enable the grid/
buttons, refresh the dataset, then turn off the UseWaitCursor. If I
execute this from Visual Studio (in Debug or Release, Run Project or
Manually selecting the executable), it works perfectly fine. But, if
I run the executable manually (straight from Explorer/Command line),
the application goes into a "Not Responding" mode and never returns.
If I attach the debugger to the process, the line that it gets stuck
on is the grid.Enabled = true. If I skip that line, it still gets
stuck, but on the BindingSource.ResetBindings(...) call.

I'll post the code below. Can anyone help me with this?

using System;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Forms;

namespace VAInvoicing
{
public partial class formMain : Form
{
private BackgroundWorker bgWorkerGet;
private BackgroundWorker bgWorkerSend;

public formMain()
{
InitializeComponent();

bgWorkerGet = new BackgroundWorker();
bgWorkerSend = new BackgroundWorker();
bgWorkerSend.WorkerReportsProgress = true;

bgWorkerGet.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bgWorkerGet_RunWork erCompleted);
bgWorkerGet.DoWork += new DoWorkEventHandler(bgWorkerGet_DoWork);

bgWorkerSend.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bgWorkerSend_RunWor kerCompleted);
bgWorkerSend.DoWork += new DoWorkEventHandler(bgWorkerSend_DoWork);
bgWorkerSend.ProgressChanged += new
ProgressChangedEventHandler(bgWorkerSend_ProgressC hanged);
}

private void formMain_Load(object sender, EventArgs e)
{
dtStart.Value = DateTime.Today.AddMonths(-1);
dtEnd.Value = DateTime.Today;
}

private void buttonGetInvoices_Click(object sender, EventArgs e)
{
this.UseWaitCursor = true;
panelFilter.Enabled = panelActions.Enabled = false;
statusLabel.Text = "Searching for Invoices...";
progressSend.Style = ProgressBarStyle.Marquee;

bgWorkerGet.RunWorkerAsync();
}

private void bgWorkerGet_DoWork(object sender, DoWorkEventArgs e)
{
eqIpaInvoice2TableAdapter.SetCommandTimeout(120);
eqIpaInvoice2TableAdapter.Fill(eqIpaInvoice2._eqIp aInvoice2,
dtStart.Value, dtEnd.Value,
ConfigurationManager.AppSettings["NameFilter"]);
}

private void bgWorkerGet_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
panelFilter.Enabled = panelActions.Enabled = true;
progressSend.Style = ProgressBarStyle.Blocks;
progressSend.Value = 0;

// Refresh the grid and clear selection
//eqIpaInvoice2BindingSource.ResetBindings(false);
gridInvoices.AutoResizeColumns();
gridInvoices.ClearSelection();

this.UseWaitCursor = false;

// Did an exception occur?
if (e.Error != null)
MessageBox.Show(this, e.Error.GetType().Name + "\n" +
e.Error.Message + "\n\n" + e.Error.StackTrace, "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private void buttonSendInvoices_Click(object sender, EventArgs e)
{
this.UseWaitCursor = true;
panelFilter.Enabled = panelActions.Enabled = false;
statusLabel.Text = "Sending " + gridInvoices.SelectedRows.Count + "
Invoice(s)...";
progressSend.Value = 0;

bgWorkerSend.RunWorkerAsync();
}

private void bgWorkerSend_DoWork(object sender, DoWorkEventArgs e)
{
int success = 0;
int failed = 0;

Random r = new Random();
DataGridViewRow[] rows = new
DataGridViewRow[gridInvoices.SelectedRows.Count];
gridInvoices.SelectedRows.CopyTo(rows, 0);
gridInvoices.ClearSelection();

foreach (DataGridViewRow row in rows)
{
// TODO: Do some work here
System.Threading.Thread.Sleep(1000);

// DEBUG -- Random number -- 30% failure rate
if (r.Next(3) != 1)
{
success++;
row.ErrorText = "";
}
else
{
failed++;
row.ErrorText = "[something went wrong]";
}

bgWorkerSend.ReportProgress((int)Math.Ceiling((int )(success +
failed) / (double)rows.Length * 100));
}

e.Result = success;
}

private void bgWorkerSend_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
progressSend.Value = e.ProgressPercentage;
}

private void bgWorkerSend_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
panelFilter.Enabled = panelActions.Enabled = true;
statusLabel.Text = "Sent " + e.Result.ToString() + " Invoice(s)";

// Make sure buttons are in the correct state
gridInvoices_SelectionChanged(this, new EventArgs());

this.UseWaitCursor = false;

// Did an exception occur?
if (e.Error != null)
MessageBox.Show(this, e.Error.GetType().Name + "\n" +
e.Error.Message + "\n\n" + e.Error.StackTrace, "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private void gridInvoices_SelectionChanged(object sender, EventArgs
e)
{
if (!bgWorkerSend.IsBusy) // Make sure we're not working on sending
now
{
// Show the user how many are selected
statusLabel.Text = gridInvoices.SelectedRows.Count + " / " +
gridInvoices.Rows.Count + " Invoice(s) Selected";

// Only enable Send if there are rows selected.
buttonSendInvoices.Enabled = gridInvoices.SelectedRows.Count 0;

// Set the default button (for pressing ENTER)
if (gridInvoices.SelectedRows.Count 0)
this.AcceptButton = buttonSendInvoices;
else
this.AcceptButton = buttonGetInvoices;
}
}
}
}

And here is the Call Stack for the "locked up" process, the last line
is the last User Code executed (or well, attempting to be executed)
is: panelFilter.Enabled = panelActions.Enabled = gridInvoices.Enabled
= true;
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Cont rol.Update() +
0x72 bytes
System.Windows.Forms.dll!
System.Windows.Forms.Control.OnEnabledChanged(Syst em.EventArgs e =
{System.EventArgs}) + 0xa7 bytes
System.Windows.Forms.dll!
System.Windows.Forms.DataGridView.OnEnabledChanged (System.EventArgs e)
+ 0xb bytes
System.Windows.Forms.dll!
System.Windows.Forms.Control.Enabled.set(bool value) + 0x59 bytes
> VAInvoicing.exe!VAInvoicing.formMain.bgWorkerGet_R unWorkerCompleted(object sender = {System.ComponentModel.BackgroundWorker}, System.ComponentModel.RunWorkerCompletedEventArgs e = {System.ComponentModel.RunWorkerCompletedEventArgs }) Line 71 + 0x26 bytes C#
Jul 24 '08 #1
1 3707
I added the symbols for the .NET Framework and stepped down through
the code. The final call made is:

SafeNativeMethods.UpdateWindow(new HandleRef(window,
InternalHandle));

which is the only line of code in the ControlUpdate method shown in
the top of the Call Stack.
Jul 24 '08 #2

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

Similar topics

8
by: Jimbo | last post by:
I'm working on a win app that reads and processes each line of an ascii file until the end of the file. Since the file's 1.6 million lines long, after a while Windows displays the "Not Responding"...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
0
by: Jonathan Wilson | last post by:
Firstly, to get msvcrt.lib, install the .NET framework SDK. The version of msvcrt.lib included there is the exact same one as comes with Visual Studio ..NET 2003. There are some other things that...
0
by: news.iq.ca | last post by:
Hello. I have created a class, "CompiledPage.vb", and I need to compile it. When I run (using the VSNet Command Prompt): ____________________________________________________________...
6
by: Botak | last post by:
Hi, I wrote an app under vb.net to calculate huge data from MS Sql server. Whenever this app is running, I could not do other work. Or else, the app will become "not responding" but actually it is...
6
by: swartzbill2000 | last post by:
Hello, I have some downloaded source code on my machine that the .net framework thinks is "not fully trusted". How can I fix this? I assume I use the 'Microsoft .NET Framework 1.1 Configuration'...
9
by: Richard Lionheart | last post by:
Hi All, I've got Visual Studio .Net installed, but I don't know it very well. So I tried to create a plain old Win32 using the command-line complier. I tried to compile: ************...
1
by: Rklawton | last post by:
I've got some CPU intensive VBA code that works just fine. However, I get the application "not responding" message in my task manager while it executes. When this happens (after a few seconds...
5
by: AAaron123 | last post by:
The aspx file includes the following: <asp:LoginView ID="LoginView1" Runat="server"> <LoggedInTemplate> <fieldset> <asp:label id="message1" runat="server" />
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.