Foreach loop does not go through the whole element in the list - C #

I have a base loop foreachthat calls a static method that makes a database connection and inserts some data. For some reason, it will only iterate over the first element of the collection when the application starts without debugging. If I debug the application and set a breakpoint in the loop foreach, it will iterate over all the elements in the collection.

If I set a breakpoint and step over the loop foreach, this will exhibit the same behavior as when starting the application without debugging.

Does anyone know what can cause this type of behavior?

Here is a simplified version of the source code:

List<MyObject> objectlist = new List<MyObject>();

//some code to populate list

foreach(MyObject myobject in objectlist)
{
    string a = "a";
    string b = "b";

    MyLibrary.UpdateDatabase(a, b);
}

(I am using Visual Studio 2008 SP1)

Update

.

+3
4

foreach, , myobject UpdateDatabase.

:

List<MyObject> objectlist = new List<MyObject>();

//some code to populate list

foreach(MyObject myobject in objectlist)
{
    MyLibrary.UpdateDatabase(myobject.a, myobject.b);
}
+1

, -, , . ( - )

, - ( catch, Console.WriteLine MessageBox.Show, , - ).

, - .

, .

+4

, , , .

, , . , , , .

, , , - . , .

+2

. , Debug - Exceptions to On?

0

Source: https://habr.com/ru/post/1718318/


All Articles