Sorry if this is a silly question, but i'd just like to be certain.

I start my app, and then immediately start a new thread to carry out some tasks while my 'main thread' (if that is the term to use) is doing something else.

Do all method calls from the new thread i started, execute from that thread?

Do all method calls from the new thread i started, execute from that thread?

Anything done on the new thread is done on the new thread. If the method you use to start the thread makes calls to other methods, they all run on the new thread.

Hmm, conflicting answers there.

From which thread is method1() executing in the code below?
I'm hoping its the spawned thread.

namespace nspace
{
    public class Program
    {
        public static void Main(string[] args)
        {

            Thread thread = new Thread(new ThreadStart(newthread));
            thread.Start();
            while (true)
            {
                Thread.Sleep(10);
            }
        }
        public static void newthread()
        {
            method1();
        }
        public static void method1()
        {
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine("method1");
                Thread.Sleep(100);
            }

            Console.ReadKey();
        }
    }
}

It is executing from a newly created thread. But this kind of coding is useless. Why would you want to call a method from a method, and without doing anything on the 1st one. Ok, mabye this is just an example code, made for testings only.

This article has been dead for over six months. Start a new discussion instead.