Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("終了するには q を押してください。");
            var factory = new Factory();
            var syain1  = new Syain()
            {
                Name = "ベテラン社員1", Age = "45"
            };
            var syain2 = new Syain()
            {
                Name = "若手社員2", Age = "19"
            };
            var syain3 = new Syain()
            {
                Name = "再雇用3", Age = "77"
            };
            var syain4 = new HakenSyain()
            {
                Name = "派遣社員1", Age = "29"
            };

            factory.Subscribe(syain1);
            factory.Subscribe(syain2);
            factory.Subscribe(syain3);
            factory.Subscribe(syain4);

            var source = new CancellationTokenSource();
            var task   = Task.Run(() => {
                var token = source.Token;
                for (; ;)
                {
                    if (token.IsCancellationRequested)
                    {
                        token.ThrowIfCancellationRequested();
                    }
                    factory.Business();
                    Console.WriteLine("");
                    Thread.Sleep(1500);
                }
            });

            for (; ;)
            {
                var key = Console.ReadKey();
                if (key.KeyChar == 'q')
                {
                    source.Cancel();
                    task.Wait();
                    break;
                }
            }
        }
Exemple #2
0
 public void OnTanpopo(Syain syain)
 {
     Console.WriteLine($"{syain.Name}:{syain.Age}歳 がたんぱぽをのせました");
 }