Пример #1
0
        private void ButtonShow_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < MainThreads.Count; ++i)
            {
                string
                    Msg = string.Format("Thread# {0}: IsAlive=\"{1}\", ThreadState=\"{2}\"", i, MainThreads[i].IsAlive, MainThreads[i].ThreadState);

                if (ListBoxMainThreadsLog.InvokeRequired)
                {
                    ListBoxMainThreadsLog.Invoke(new MethodInvoker(delegate { ListBoxMainThreadsLog.Items.Add(Msg); }));
                }
                else
                {
                    ListBoxMainThreadsLog.Items.Add(Msg);
                }
            }
        }
Пример #2
0
        void RemoveThread(int Id)
        {
            object
                forLock = new object();

            lock (forLock)
            {
                if (MainThreads.ContainsKey(Id))
                {
                    string
                        Msg = string.Format("Thread# {0} has been removed (IsAlive=\"{1}\", ThreadState=\"{2}\")", Id, MainThreads[Id].IsAlive, MainThreads[Id].ThreadState);

                    MainThreads.Remove(Id);

                    if (MainThreads.Count == 0)
                    {
                        if (ButtonStop.InvokeRequired)
                        {
                            ButtonStop.Invoke(new MethodInvoker(delegate { ButtonStop.Enabled = false; }));
                        }
                        else
                        {
                            ButtonStop.Enabled = false;
                        }

                        if (ButtonDoIt.InvokeRequired)
                        {
                            ButtonDoIt.Invoke(new MethodInvoker(delegate { ButtonDoIt.Enabled = true; }));
                        }
                        else
                        {
                            ButtonDoIt.Enabled = true;
                        }
                    }

                    if (ListBoxMainThreadsLog.InvokeRequired)
                    {
                        ListBoxMainThreadsLog.Invoke(new MethodInvoker(delegate { ListBoxMainThreadsLog.Items.Add(Msg); }));
                    }
                    else
                    {
                        ListBoxMainThreadsLog.Items.Add(Msg);
                    }
                }
            }
        }