ss

CSharp · Console

/Program.cs

using System;
using System.Threading;


public class Program
{
    private static readonly object _lock = new object();
    public static void Main()
    {
        //Console.WriteLine("Start");
        for (var i = 0; i < 10; i++)
        {
            //Console.WriteLine("Start "+i); 
            System.Threading.Thread thread = new System.Threading.Thread(() => ExecuteInBackground(i));
            thread.IsBackground = true;
            thread.Start();
        }
        //Console.WriteLine("End");
        //Console.ReadLine();
    }

    private static void ExecuteInBackground(Object obj)
    {
        lock (_lock)
        {
            //Thread.Sleep(10);
            Console.WriteLine("A "+obj);
            test.ttt(obj);
        }
    }
}


public static class test
{
    
    public static void ttt(object obj)
	{
		Console.WriteLine("B "+ obj);
    }
}
;