Пример #1
0
        private static void Main(string[] args)
        {
            var handle  = new EventWaitHandle(true, EventResetMode.AutoReset);
            var handle2 = new EventWaitHandle(true, EventResetMode.ManualReset);
            var handle3 = new AutoResetEvent(true);

            CountdownEvent ce = new CountdownEvent(4);

            WaitHandle.WaitAny(new[] { ce.WaitHandle });

            var instance = new SingleThreaded();

            new Thread(
                () =>
            {
                instance.OneCallInstance1();
                ce.Signal();
            }).Start();

            new Thread(
                () =>
            {
                lock (instance)
                {
                    Console.WriteLine("Main");
                    Console.ReadLine();
                    Console.WriteLine("Main");
                }
                ce.Signal();
            }).Start();

            new Thread(
                () =>
            {
                instance.OneCallInstance2();
                ce.Signal();
            }).Start();

            new Thread(
                () =>
            {
                instance.OneCallLockThis();
                ce.Signal();
            }).Start();

            // new Thread(() => {

            // SingleThreaded.OneCallStatic1();
            // }).Start();

            // new Thread(() => {

            // SingleThreaded.OneCallStatic2();
            // }).Start();
            ce.Wait();

            // Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var handle = new EventWaitHandle(true, EventResetMode.AutoReset);
            var handle2 = new EventWaitHandle(true, EventResetMode.ManualReset);
            var handle3 = new AutoResetEvent(true);

            CountdownEvent ce = new CountdownEvent(4);

            WaitHandle.WaitAny(new WaitHandle[] { ce.WaitHandle });

            var instance = new SingleThreaded();
            new Thread(() => {

                instance.OneCallInstance1();
                ce.Signal();
            }).Start();

            new Thread(() => {

                lock (instance) {
                    Console.WriteLine("Main");
                    Console.ReadLine();
                    Console.WriteLine("Main");

                }
                ce.Signal();
            }).Start();

            new Thread(() => {

                instance.OneCallInstance2();
                ce.Signal();
            }).Start();

            new Thread(() => {

                instance.OneCallLockThis();
                ce.Signal();
            }).Start();

            //new Thread(() => {

            //    SingleThreaded.OneCallStatic1();
            //}).Start();

            //new Thread(() => {

            //    SingleThreaded.OneCallStatic2();
            //}).Start();

            ce.Wait();
            //Console.ReadLine();
        }