コード例 #1
0
ファイル: AlBahariPart1.cs プロジェクト: saketarya/padhaai
        public void CallMeFromMainThread()
        {
            // create an instance
            ThreadsShareInstanceVaraibles tt = new ThreadsShareInstanceVaraibles();
            Task t = new Task(tt.ThreadSafeGo);

            t.Start();
            tt.ThreadSafeGo();
        }
コード例 #2
0
ファイル: AlBahariPart1.cs プロジェクト: saketarya/padhaai
        public void UsingThreadJoin()
        {
            // create an instance
            ThreadsShareInstanceVaraibles tt = new ThreadsShareInstanceVaraibles();
            Task t = new Task(tt.ThreadUnsafeGo);

            t.Start();
            t.Wait(); // waits till t completes. That will have "done" set to true
            tt.ThreadUnsafeGo();
        }
コード例 #3
0
ファイル: AlBahariPart1.cs プロジェクト: saketarya/padhaai
        public void WhatIfForgroundThreadEndsBeforeBackgroundThread()
        {
            // create an instance
            ThreadsShareInstanceVaraibles tt = new ThreadsShareInstanceVaraibles();
            Task t = Task.Factory.StartNew(tt.ThreadUnsafeGo)
                     .ContinueWith((x) => Console.WriteLine("hello!"));

            t.Wait(); // waits till t completes. That will have "done" set to true
            tt.ThreadUnsafeGo();

            Task t2 = Task.Factory.StartNew(() => {
                Thread.Sleep(10);
                Console.WriteLine("Tata !!");
            });

            //It may not print "Tata!!" is you do not wait for thread t2.
        }