Im having some trouble with a C# application I have written. Usually I am able to find an answer on this excellent forum but unfortunately Im not quite sure how to phrase a search to help me find this answer.
The application is a C# app written on Visual Studio 2008 using .Net 2.0.
Basically I have a Gridview embedded in a Windows Form with textbox and button control. Once the button is pressed a background worker thread begins that uses the textbox.text entry to search a SQL database and return the results as a selection of rows. The Form also has a status bar that runs to display the progress of the query. Once completed the background worker calls a delegate method to refresh the GridView and Display the results.
If the SQL Query returns a list of results that is larger than the display window the application freezes and becomes non responsive. Essentially if I maximise the app to full screen the grid view can display up to 25 records. If there are 24 or less results the app works without issue, Over 25 and it fails.
Strangely it will always work without issue no matter how many results are returned when run from Visual Studio (debug or release), however if I double click the exe in Windows explorer it fails. My code is below. I am stuck at this point as I dont quite know why it is working in VS but not when I run it standalone. Any help or direction would be appreciated.
public delegate void RefreshGUIDelegate1();
public RefreshGUIDelegate1 myDelegate1;
//Button that shows the Progress Bar and begins the Background Thread
private void button1_Click(object sender, EventArgs e)
button1.Enabled = false;
myDelegate1 = new RefreshGUIDelegate1(DoRefreshGUIDelegate1);
toolStripProgressBar1.Visible = true;
//Background Worked DOWork function that returns the results to the database
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
this.spSearchEADProductFamilyNameTableAdapter.ClearBeforeFill = true;
catch (Exception msg5)
MessageBox.Show("Database Error: " + msg5.Message.ToString());
//Run Worker Completed that turns off the Progress Bar and calls the Delegate
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
toolStripProgressBar1.Visible = false;
//Delegate that Refreshes the Grid View with Data from the Table Adapter
public void DoRefreshGUIDelegate1()
toolStripStatusLabel1.Text = "Number of Records Returned = " + dataGridView1.RowCount.ToString();
catch (Exception msg4)
MessageBox.Show("Database Error: " + msg4.Message.ToString());
//Tick Function for the Progress Bar
private void timer1_Tick(object sender, EventArgs e)
TimeSpan ts = DateTime.Now.Subtract(StartDate);
string sTime = " Updating..." + ts.Minutes.ToString("00") +
":" + ts.Seconds.ToString("00") +
":" + ts.Milliseconds.ToString("000");
toolStripStatusLabel1.Text = sTime;
if (toolStripProgressBar1.Value == toolStripProgressBar1.Maximum)
toolStripProgressBar1.Value = 0;