コード例 #1
0
ファイル: LongProcess.cs プロジェクト: ssor/csharpDemos
        public void Send_mail(ComandMail mail)
        {
            m_mailbox_sync.WaitOne();
            m_mailbox_sync.Reset();

            mailbox.Add(mail);

            m_mailbox_sync.Set();
        }
コード例 #2
0
ファイル: LongProcess.cs プロジェクト: ssor/csharpDemos
        // Function runs in worker thread and emulates long process.
        public void Run()
        {
            while (true)
            {
                // check if thread is cancelled
                if (m_EventStop.WaitOne(0, true))
                {
                    // clean-up operations may be placed here
                    // ...

                    // inform main thread that this thread stopped
                    m_EventStopped.Set();

                    return;
                }

                // make step
                //s = "Step number " + i.ToString() + " executed";
                m_mailbox_sync.WaitOne();
                m_mailbox_sync.Reset();
                ComandMail cm = null;
                if (mailbox.Count > 0)
                {
                    cm = mailbox[0];
                    mailbox.RemoveAt(0);
                }

                m_mailbox_sync.Set();
                if (cm == null)
                {
                    continue;
                }
                //执行命令,修改此处执行具体功能
                Debug.WriteLine(cm.toString());
                Thread.Sleep(300);

                // Make synchronous call to main form.
                // MainForm.AddString function runs in main thread.
                // To make asynchronous call use BeginInvoke
                //m_form.Invoke(m_form.m_DelegateAddString, new Object[] { s });
            }

            // Make asynchronous call to main form
            // to inform it that thread finished
            //m_form.Invoke(m_form.m_DelegateThreadFinished, null);
        }