// 這個是 一次次執行,只是達到了控制另一個類中的變數的目的,並沒有達到想要測試是否由於執行時間慢,還沒有執行到函式(需要依據這個變數(isCallBox) 做分類執行的目的)這個變數就又改變了,現在用定時函式測試,然後觀察----------如果會改變,需要考慮用鎖,是否會達到不改變的目的
namespace ConsoleApplication11
{
    class Program
    {

        static int T { get; set; } = 1;
      //  static bool isCallBox = false;

        static void Main(string[] args)
        {
            T = 60;

            var I = (char)T;


            for(int i=0;i<100;i++)
            {
                if(i%2==0)
                {
                    Test.isCallBox = false;
                }
                else
                {
                    Test.isCallBox = true;
                }

                Test.PrintText();
               // System.Threading.Thread.Sleep(500);

            }

            //Class1 c1 = new Class1();
            //AutoMapper.Mapper.Initialize(cfg => cfg.CreateMap<Class1, Class2DTO>().ForMember(d => d.ie, opt => opt.MapFrom(i => i.i)));


            //var c2=AutoMapper.Mapper.Map<Class2DTO>(c1);

            Console.WriteLine(I);

            Console.Read();
        }

     
    }

    public class Test
    {
        public static bool isCallBox=false;

        public static void PrintText()
        {
          
            //isCallBox = false;
            // System.Threading.Thread.Sleep(500);
            if (isCallBox)
            {
                Console.WriteLine("is true;");
            }
            else
            {
                Console.WriteLine("is false");
            }
        }
    }
}

//output 
  is false;
  is true;
  is false
  is true;
...... <

// 這樣就是不規則輸出

namespace ConsoleApplication11
{
    class Program
    {
        static private  Timer _jobTimer;
        static int i = 0;

        static int T { get; set; } = 1;
      //  static bool isCallBox = false;

        static void Main(string[] args)
        {
            T = 60;

            var I = (char)T;

            //for(int i=0;i<100;i++)
            //{
            //    if(i%2==0)
            //    {
            //        Test.isCallBox = false;
            //    }
            //    else
            //    {
            //        Test.isCallBox = true;
            //    }

            //    Test.PrintText();
            //   // System.Threading.Thread.Sleep(500);

            //}

            //Class1 c1 = new Class1();
            //AutoMapper.Mapper.Initialize(cfg => cfg.CreateMap<Class1, Class2DTO>().ForMember(d => d.ie, opt => opt.MapFrom(i => i.i)));


            //var c2=AutoMapper.Mapper.Map<Class2DTO>(c1);
            StartJob();
            Console.WriteLine(I);

            Console.Read();
        }

        public static void StartJob()
        {
            _jobTimer = new System.Timers.Timer();
            _jobTimer.Interval = 500;
            _jobTimer.Elapsed += new ElapsedEventHandler(Timer_ChangeBoolValue);
            _jobTimer.Start();
        }

        private static void Timer_ChangeBoolValue(object sender, ElapsedEventArgs e)
        {
            if (i % 2 == 0)
            {
                Test.isCallBox = false;
            }
            else
            {
                Test.isCallBox = true;
            }
            i++;
            Test.PrintText();
        }
    }

    public class Test
    {
        public static bool isCallBox=false;

        public static void PrintText()
        {
          
            //isCallBox = false;
            System.Threading.Thread.Sleep(6500);
            if (isCallBox)
            {
                Console.WriteLine("is true;");
            }
            else
            {
                Console.WriteLine("is false");
            }
        }
    }
}

// output

is false 
is false
is true
is false
is true ...   非規則輸出  , 加lock看看是否會杜絕非規則輸出