Hi

I have a problem with a console app. It will not run methods in sequence but rather runs them all at the same time? I have put some example code below. The problem is it will run the methods below at the same time, without waiting for the frs to finish? If I remove the foreach statement it does not help. I do not have this problem with a windows forms program, only console?

Method("string1");
Method("string2");
Method("string3");
Method("string4");
class Program
    {
        static void Main(string[] args)
        {
            Transfer xfer = new Transfer();
            xfer.Run();
        }
    }

    public class Transfer
    {
        public void Run()
        {
            List<string> myList= new List<string>();
            myList.Add("string1");
            myList.Add("string2");
            myList.Add("string3");
            myList.Add("string4");

              Method(string i)
              {
                   //code to do whatever
               }
              foreach(string i in myList)
              {
                  Method(i);
               }
         }
    }

I can assure you they run sequentially and not at the same time. You also posted code that won't compile so I suspect your problem lies elsewhere. Please post your complete code so we can take a look at it.

i rearrange your code and runned. As far as i know its working sequentially well.

here is the code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Transfer xfer = new Transfer();
            xfer.Run();
        }
    }

    public class Transfer
    {
        public void Run()
        {
            List<string> myList= new List<string>();
            myList.Add("string1");
            myList.Add("string2");
            myList.Add("string3");
            myList.Add("string4");

            foreach(string i in myList)
            {
                Method(i);
            }
        }

        public void Method(string i)
        {
            Console.WriteLine(i);
        }
    }

}
Comments
Welcome to daniweb! your first post was excellent

Sorry, looking deeper into the code I found that an external process (System.Diagnostic.Process) was being called and was the cause of the problem. MY apologies but thanks for all that responded. The clarification that they would run is sequence forced me to look elsewhere so it helped me greatly.
thanks

This question has already been answered. Start a new discussion instead.