472,954 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3605
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: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.