123456789101112131415161718192021222324252627282930313233343536373839 |
- using CommonLang;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- namespace CommonFroms.G2D
- {
- public class G2DTimer : System.Windows.Forms.Timer
- {
- // 内部主线程命令 //
- private SyncMessageQueue<Action> mTasks = new SyncMessageQueue<Action>();
- public G2DTimer() { }
- public G2DTimer(IContainer container) : base(container) { }
- /// <summary>
- /// 保证在Task内部执行的代码线程安全
- /// </summary>
- /// <param name="task"></param>
- public void QueueTask(Action task)
- {
- mTasks.Enqueue(task);
- }
- private void do_task(Action task)
- {
- task.Invoke();
- }
- protected override void OnTick(EventArgs e)
- {
- base.OnTick(e);
- mTasks.ProcessMessages(do_task);
- }
- }
- }
|