I have a winforms project which depends on a custom library. Everything with the app is working fine except a problem I can not pin down. Basically I have a form which is created from another form which displays it as a dialog:
DataItems.ImportForm frmImportTextDelimited = new DataItems.ImportForm();
frmImportTextDelimited.ShowDialog();
This dialog form populates a dropdown list from the SqlServer using the below function which is from a class library in the solution:
public class AuthorityTypeSearcher
{
public List<IntValuePair> GetAllAuthorityTypes()
{
List<IntValuePair> returnList = new List<IntValuePair>();
using (var conn = new SqlConnection(Globals.ConnString))
{
var cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT FROM tblAuthorityTypes";
conn.Open();
IntValuePair ivp;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ivp = new IntValuePair();
ivp.TheInt = Convert.ToInt32(rdr["ID"]);
ivp.TheValue = rdr["AuthorityType"].ToString() ;
}
}
return returnList;
}
This function never returns a value, so I set a breakpoint on the line:
conn.Open();
When the code executes, the Visual studio correctly breaks to this line. What is making me crazy is that when I step forward to the line:
SqlDataReader rdr = cmd.ExecuteReader();
The debugger will not move forward to the next line, and code execution appears to return to the UI (the form is displayed). What is also strange is that if I interact with the form (i.e. click a button on the form which populates another field), the debugger breaks again, I return to visual studio, which correctly "breaks" to the line related to that operation. It seems like, for whatever reason, when I get to the line that creates the data reader, code execution simply "leaves" the library and returns to the winforms app.
When code execution appears to have returned to the UI, if I return to visual studio it appears that code execution is continuing, at least I can not click "continue" (play). The code execution is not "paused".
What is also strange is that if I close the form (dialog), it breaks back into the debugger on the line from the main form on the line:
frmImportTextDelimited.ShowDialog();
as though I were still debugging.
Hopefully this makes sense? I can't figure out why, when debugging, I cant step past the line where I create the data reader, and why code execution goes back to the UI, but returns to the debugger with the dialog is closed. No error is ever thrown.
Thanks for any advice!