The program works differently when I enter and when I set the function over in debug mode

I have a GetAlertData() function that returns a Datatable. I call it like:

 var dt = GetAlertData() 

Debug mode behavior:

Case 1: When I do F11 all the time and go to the GetAlertData function, everything works fine and I get the correct table

Case 2: When I do F10 on this function and step over it, GetAlertData returns a table with all values ​​filled in as zero (incorrect). (The columns of my table are all floating point data types)

In release mode, the behavior is the same as pressing F10 in debug mode, that is, I get all zeros.

Any ideas on what could be causing, or that I might try to find a reason? Thanks..

Edit: my GetAlertData function is something like this.

 internal static DataSet GetAlertData() { using (var sqlConnection = new SqlConnection(Constants.ConnectionString)) { const string sproc = @"[spo_GetAlertData]"; var cmd = new SqlCommand(sproc, sqlConnection) {CommandType = CommandType.StoredProcedure}; cmd.Parameters.Add("@TimeWindow", SqlDbType.Int); cmd.Parameters["@TimeWindow"].Value =2 cmd.Parameters.Add("@ThresholdTime", SqlDbType.Int); cmd.Parameters["@ThresholdTime"].Value = 2 var dsAnalysis = new DataSet(); var da = new SqlDataAdapter(cmd); da.Fill(dsAnalysis); if (dsAnalysis.Tables.Count > 0 && dsAnalysis.Tables[0].Rows.Count > 0) return dsAnalysis; return null; } } 
+4
source share
3 answers

You should consider the difference in execution time using F11 and F10 (respectively, starting and stepping methods). F11 goes into a function, thereby keeping you in this flow of logic longer than F10, which executes on the code, allowing it to execute at full speed.

The fact is that you may well have a synchronization / thread problem, which is easier when the application has more processing time, due to the fact that you have more time to go to the code using F11. That is why the release of more behavior corresponds to the behavior of F10, faster execution.

I suggest embellishing something like Thread.Sleep(250) around the problem area will help too, but I do not recommend this one . This absolutely last resort action is best used to test the time hypothesis. You need to find out what works at the same time, what can cause it.

+2
source

Without seeing the source code for GetAlertData, I can only assume that you have created some clock variables that access the property or something with side effects that change the result. When you enter the GetAlertData method, the clock falls into scope.

+1
source

The most likely problem is that you have a property or .ToString that has side effects that are evaluated in the autos / locals / watch window in step. In the case of F11, this property is placed in one of these windows, evaluated, and its side effect makes the script work. In the F10 script, this does not happen, and the script fails.

You can easily verify this by disabling implicit functioning.

  • Tools β†’ Options
  • Debugger
  • Uncheck the box next to β€œEnable implicit property and calls.”
  • Repeat your script
+1
source

All Articles