public Rect() { Id = int.Parse(DateTime.Today.ToString("yyddmmss")); Text = string.Empty; Size = new Size(100, 100); Location = new Point(100, 100); Alive = true; RectThread.FromCurrent().AddRect(this); }
public Rect(int id, string text, Size size, Point location) { Id = id; Text = text; Size = size; Location = location; Alive = true; RectThread.FromCurrent().AddRect(this); Console.WriteLine(Id + "号矩形已创建"); }
/// <summary> /// 获取与当前线程相关的RectThread对象 /// </summary> /// <returns></returns> public static RectThread FromCurrent() { var id = Thread.CurrentThread.ManagedThreadId; if (_allRectThreads.ContainsKey(id)) { return(_allRectThreads[id]); } var thread = new RectThread(); _allRectThreads.Add(id, thread); return(_allRectThreads[id]); }
/// <summary> /// 执行一次信号循环,进行一次信号处理 /// </summary> public static void DoSignal() => RectThread.FromCurrent().StartLoop(2, null);
/// <summary> /// 开启信号循环 /// </summary> /// <param name="rect">主rect</param> public static void Start(Rect rect) => RectThread.FromCurrent().StartLoop(1, rect);
protected override void OnPositionChanged(PositionChangedEventArgs e) { RectThread.SendSignal(Id, 1, e.Size, e.Location); base.OnPositionChanged(e); }