Пример #1
0
        public DownloadState(StatesContent content)
        {
            this.Content = content;
            this.Sucusess = false;

            Random random = new Random();
            int time = random.Next(3) + 1;
            this.timer = new Timer(time*1000);//实例化Timer类,设置间隔时间为1000毫秒;
            this.timer.Elapsed += new ElapsedEventHandler(theout);//到达时间的时候执行事件;
            this.timer.AutoReset = false;//设置是执行一次(false)还是一直执行(true);
            //t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
        }
Пример #2
0
 public StopDownloadState(StatesContent content)
 {
     this.Content = content;
 }
Пример #3
0
 public StopPlayState(StatesContent content)
 {
     this.Content = content;
 }
Пример #4
0
 static void test_state_mode()
 {
     /*
      * 状态模式:允许对象在内部状态改变时改变它的行为,对象看起来好像修改了它的类。(客户不清楚内部状态间的转换,策略模式则需要客户了解状态间的转换)时。
      */
     Console.WriteLine("\n---------------- test state --------------------\n");
     StatesContent content = new StatesContent();
     content.addState(new DownloadState(content));
     content.addState(new StopDownloadState(content));
     content.addState(new PlayState(content));
     content.addState(new StopPlayState(content));
     content.download();
     Console.Read();
 }