static void Main(string[] args) { // Delegate with method PrintFirst for second timer TimerRun action = new TimerRun(PrintFirst); Timer timer1 = new Timer(action, "Tik : 1 sec", 1); // Delegate with method PrintFirst for second timer action = new TimerRun(PrintSecond); Timer timer2 = new Timer(action, "Taak : 2 sec", 2); // Start first timer Thread thread = new Thread(new ThreadStart(timer1.Run)); Console.WriteLine("Timer #1 started!"); thread.Start(); // Start second timer thread = new Thread(new ThreadStart(timer2.Run)); Console.WriteLine("Timer #2 started!"); thread.Start(); // Wait to synhronize main thread with timers treads Thread.Sleep(10000); // Stop first timer thread = new Thread(new ThreadStart(timer1.Stop)); Console.WriteLine("Timer #1 stoped!"); thread.Start(); // Wait to synhronize main thread with timers treads Thread.Sleep(6000); // Stop second timer thread = new Thread(new ThreadStart(timer2.Stop)); Console.WriteLine("Timer #2 stoped!"); thread.Start(); // Wait to synhronize main thread with timers treads Thread.Sleep(2000); Console.WriteLine("That's all folks!"); Console.WriteLine(); // Print info how many times run each timer Console.WriteLine("Timer #1 counts {0} times", timer1.RepetitionCount); Console.WriteLine("Timer #2 counts {0} times", timer2.RepetitionCount); }
public void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { GameObject timerObject = GameObject.Find("Controller"); TimerRun timer = timerObject.GetComponent <TimerRun>(); timer.MissionComplete = true; } }
private string str; // Stores a string to print #endregion Fields #region Constructors // Constructor public Timer(TimerRun func, string str, int sec = 3) { if (func == null) { throw new NullReferenceException("Creation of Null delegate is not possible!"); } this.runList = func; this.delaySeconds = sec * 1000; this.str = str; }
private string str; // Stores a string to print // Constructor public Timer(TimerRun func, string str, int sec = 3) { if (func == null) { throw new NullReferenceException("Creation of Null delegate is not possible!"); } this.runList = func; this.delaySeconds = sec * 1000; this.str = str; }
private void pause_Click(object sender, EventArgs e) { if (!eluosIsRun) { return; } if (TimerRun.Enabled) { TimerRun.Stop(); pause.Text = "|>"; } else { TimerRun.Start(); pause.Text = "||"; } }
public void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == CollisionTarget) { if (collision.gameObject.tag == "Player") { GameObject timerObject = GameObject.Find("Controller"); if (timerObject == null) { throw new MissingReferenceException(); } TimerRun timer = timerObject.GetComponent <TimerRun>(); if (timer == null) { throw new MissingComponentException(); } if (IsInvincible) { timer.MissionComplete = false; timer.MissionFailed = true; } else { float yVelocity = collision.gameObject.transform.rigidbody2D.velocity.y; if (yVelocity < 0) { Debug.Log("Enemy will lose..." + yVelocity); Destroy(this.gameObject); } else { timer.MissionComplete = false; timer.MissionFailed = true; } } } } }
private void start_Click(object sender, EventArgs e) { //初始化背景、数组 GameLabel.Text = "Come On!"; GameLabel.ForeColor = Color.Lime; for (int i = 0; i < W * H; i++) { PicBox[i].BackColor = Color.Black; PicBox[i].BorderStyle = BorderStyle.None; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { GameArry[i, j] = 0; } } for (int i = 0; i < 4 * 4; i++) { NextPic[i].BackColor = Color.Black; NextPic[i].BorderStyle = BorderStyle.None; } //speed int speed = 100 * (SpeedComBox.SelectedIndex + 1); TimerRun.Interval = speed; TimerRun.Start(); //score Score = 0; ScoreLabel.Text = Score.ToString(); //禁用comboBox1 SpeedComBox.Enabled = false; //下一个方块清空,重新创造,并且运行 NextTetromino = 0; Create(); TimerRun.Enabled = true; eluosIsRun = true; }
/// <summary> /// Type=1003 应用被启用<para/> /// 处理 酷Q 的插件启动事件回调 /// </summary> /// <param name="sender">事件的触发对象</param> /// <param name="e">事件的附加参数</param> public void AppEnable(object sender, EventArgs e) { // 当应用被启用后,将收到此事件。 // 如果酷Q载入时应用已被启用,则在_eventStartup(Type=1001,酷Q启动)被调用后,本函数也将被调用一次。 // 如非必要,不建议在这里加载窗口。(可以添加菜单,让用户手动打开窗口) Common.IsRunning = true; LuaEnv.LuaEnv.RunLua("", "envent/AppEnable.lua"); TimerRun.TimerStart(); if (Common.CqApi.GetLoginQQ() == 751323264)//默认不开启tcp服务器 { TcpServer.Start(); } //第一次启动,clone下来整个项目 Task.Run(() => { string gitPath = Common.AppDirectory + "git/"; if (Repository.IsValid(gitPath)) { return;//已存在工程,不用再初始化了 } Common.CqApi.AddLoger(LogerLevel.Warning, "第一次启动的提示", "这不是错误提示\r\n" + "正在下载初始脚本,请稍后"); try { Repository.Clone("https://gitee.com/chenxuuu/receiver-meow.git", gitPath); } catch { Common.CqApi.AddFatalError("lua插件警告:无法下载git项目,请检查网络然后重启酷Q!"); return; //clone失败,还原 } if (!Directory.Exists(Common.AppDirectory + "lua")) //如果已有这俩文件夹,那么就不用管了 { Tools.CopyDirectory(gitPath + "appdata/lua", Common.AppDirectory + "lua"); Tools.CopyDirectory(gitPath + "appdata/xml", Common.AppDirectory + "xml"); } Common.CqApi.AddLoger(LogerLevel.Warning, "第一次启动的提示", "这不是错误提示\r\n" + "初始脚本下载完成,可以使用了\r\n" + "请注意更改初始配置"); }); }