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);
        }
    }

}
commented: Welcome to daniweb! your first post was excellent +4

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

I'm glad you a solution for your problem.

Please mark this thread as solved and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.