Ejemplo n.º 1
0
        private void button_AddThread_Click(object sender, EventArgs e)
        {
            direction Dir = direction.down;

            if (x0 == 0)
            {
            }
            else if (x1 == 0)
            {
                Dir = direction.right;
                x1++;
            }
            else if (x2 == 0)
            {
                Dir = direction.up;
                x2++;
            }
            else if (x3 == 0)
            {
                Dir = direction.left;
                x3++;
            }
            if (Dir == direction.down && x0 > 0)
            {
                return;
            }
            else
            {
                x0++;
            }
            ThreadInfoPanel TPanel = new ThreadInfoPanel();

            TPanel.mainThread        = ShowMsg;
            TPanel.Btn_ActClick      = Btn_ActClick;
            TPanel.Btn_PriorityClick = Btn_PriorityClick;
            TPanel.Btn_JoinClick     = Btn_JoinClick;
            TPanel.Refresh_Click     = Refresh_Click;
            Thread thread = new Thread(TPanel.ThreadFunc);

            thread.Name          = Dir.ToString();//DateTime.Now.ToLongTimeString();
            TPanel.DirTy         = Dir;
            TPanel.Location      = new Point(PairWidth, 0);
            PairWidth           += TPanel.Width;
            TPanel.GroupBox.Text = thread.Name;
            TPanel.Tag           = thread.ManagedThreadId;
            this.panel_Func.Controls.Add(TPanel);
            this.panel_Func.Height = TPanel.Height;
            thread.Start();
            if (!TPDic.ContainsKey(thread.ManagedThreadId))
            {
                TPDic.Add(thread.ManagedThreadId, TPanel);
            }
            if (!ThreadDic.ContainsKey(thread.ManagedThreadId))
            {
                ThreadDic.Add(thread.ManagedThreadId, thread);
            }
        }
Ejemplo n.º 2
0
        private void Refresh_Click(object Sender, EventArgs e)
        {
            ThreadInfoPanel TPanel = Sender as ThreadInfoPanel;
            int             Id     = Convert.ToInt32(TPanel.Tag);

            if (ThreadDic.ContainsKey(Id))
            {
                Thread CurThread = ThreadDic[Id];
                TPanel.SetThreadInfo(CurThread);
            }
        }
Ejemplo n.º 3
0
        public void ShowPanelMsg(ThreadInfoPanel sender, object msg)
        {
            sender.Msg = msg.ToString();
            int Id = Convert.ToInt32(sender.Tag);

            if (ThreadDic.ContainsKey(Id))
            {
                sender.SetThreadInfo(ThreadDic[Id]);
            }
            //if (sender.InvokeRequired)
            //    sender.SetThreadInfo();
        }
Ejemplo n.º 4
0
        private void ShowMsg(object msg)
        {
            lock (this)
            {
                if (TPDic.ContainsKey(Thread.CurrentThread.ManagedThreadId))
                {
                    ThreadInfoPanel TPanel = TPDic[Thread.CurrentThread.ManagedThreadId];
                    if (TPanel.InvokeRequired)
                    {
                        //TPanel.SetThreadInfo(Thread.CurrentThread);
                        this.ShowMagFunc = ShowPanelMsg;
                        this.Invoke(this.ShowMagFunc, TPanel, msg);
                        switch (TPanel.DirTy)
                        {
                        case direction.down:
                        {
                            this.ButtonMove = moveDown;
                        }
                        break;

                        case direction.right:
                        {
                            this.ButtonMove = moveRight;
                        }
                        break;

                        case direction.up:
                        {
                            this.ButtonMove = moveUp;
                        }
                        break;
                        }
                        this.Invoke(this.ButtonMove);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void Btn_PriorityClick(object Sender, EventArgs e)
        {
            ThreadInfoPanel TPanel = Sender as ThreadInfoPanel;
            int             Id     = Convert.ToInt32(TPanel.Tag);

            if (ThreadDic.ContainsKey(Id))
            {
                Thread CurThread = ThreadDic[Id];
                if (CurThread.IsAlive)
                {
                    int CurPriority = (int)CurThread.Priority;
                    if (CurPriority >= 4)
                    {
                        CurPriority = 0;
                    }
                    else
                    {
                        CurPriority++;
                    }
                    CurThread.Priority = (ThreadPriority)CurPriority;
                }
                TPanel.SetThreadInfo(CurThread);
            }
        }
Ejemplo n.º 6
0
        private void Btn_ActClick(object Sender, EventArgs e)
        {
            ThreadInfoPanel TPanel = Sender as ThreadInfoPanel;
            int             Id     = Convert.ToInt32(TPanel.Tag);

            if (ThreadDic.ContainsKey(Id))
            {
                if (ThreadDic[Id].IsAlive)
                {
                    ThreadDic[Id].Abort();
                    if (TPDic.ContainsKey(ThreadDic[Id].ManagedThreadId))
                    {
                        TPDic.Remove(ThreadDic[Id].ManagedThreadId);
                    }
                    TPanel.SetThreadInfo(ThreadDic[Id]);
                }
                else
                {
                    Thread thread = new Thread(TPanel.ThreadFunc);
                    thread.Name          = DateTime.Now.ToLongTimeString();
                    TPanel.Tag           = thread.ManagedThreadId;
                    TPanel.num           = 0;
                    TPanel.GroupBox.Text = thread.Name;
                    if (!TPDic.ContainsKey(thread.ManagedThreadId))
                    {
                        TPDic.Add(thread.ManagedThreadId, TPanel);
                    }
                    else
                    {
                        TPDic[thread.ManagedThreadId] = TPanel;
                    }
                    if (!ThreadDic.ContainsKey(thread.ManagedThreadId))
                    {
                        ThreadDic.Add(thread.ManagedThreadId, thread);
                    }
                    else
                    {
                        ThreadDic[Id] = thread;
                    }
                    thread.Start();
                    TPanel.SetThreadInfo(thread);
                }
            }
            //if(Sender is ThreadInfoPanel)
            //{
            //    ThreadInfoPanel TPanel = Sender as ThreadInfoPanel;
            //    int ManagedThreadId = -1;
            //    foreach (KeyValuePair<int, ThreadInfoPanel> pair in TPDic)
            //    {
            //        if(TPanel == pair.Value)
            //        {
            //            ManagedThreadId = pair.Key;
            //        }
            //    }
            //    foreach(ProcessThread Thread in Process.GetCurrentProcess().Threads)
            //    {
            //        if(Thread.Id== ManagedThreadId)
            //        {
            //            Thread.ThreadState
            //        }
            //    }
            //}
        }