Esempio n. 1
0
        public void ThreadMain()
        {
            int nTimeLeft = m_nTimeOut; // 剩下的时间

            WaitHandle[] events = new WaitHandle[1];

            events[0] = eventClose;


            if (m_nTimeOut == -1)
            {
                WaitHandle.WaitAny(events);
                return;
            }

            int nPerTime = 1000;

            while (true)
            {
                int nThisTime = Math.Min(nTimeLeft, nPerTime);

                int index = WaitHandle.WaitAny(events, nThisTime, false);

                if (index == WaitHandle.WaitTimeout)
                {
                    // 修改标题

                    string strText = m_strTitleText + " (" + Convert.ToString(nTimeLeft / 1000) + " 秒后本对话框会自动关闭)";

                    // 注意这里是多线程操作,需要间接调用
                    if (this.InvokeRequired == true)
                    {
                        Delegate_SetTitleText d = new Delegate_SetTitleText(SetTitleText);
                        try
                        {
                            this.Invoke(d, new object[] { strText });
                        }
                        catch (ObjectDisposedException)
                        {
                            return;
                        }
                    }
                    else
                    {
                        base.Text = strText;
                    }

                    if (nThisTime < nPerTime) // 最后一次已经作完
                    {
                        if (this.InvokeRequired == true)
                        {
                            Delegate_CloseWindow d = new Delegate_CloseWindow(CloseWindow);
                            this.Invoke(d);
                        }
                        else
                        {
                            this.Close();
                        }
                        this.DialogResult = System.Windows.Forms.DialogResult.Retry;
                        return;
                    }
                    nTimeLeft -= nPerTime;
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 2
0
        public void ThreadMain()
        {
            int nTimeLeft = m_nTimeOut;	// 剩下的时间

            WaitHandle[] events = new WaitHandle[1];

            events[0] = eventClose;


            if (m_nTimeOut == -1)
            {
                WaitHandle.WaitAny(events);
                return;
            }

            int nPerTime = 1000;


            while (true)
            {
                int nThisTime = Math.Min(nTimeLeft, nPerTime);

                int index = WaitHandle.WaitAny(events, nThisTime, false);

                if (index == WaitHandle.WaitTimeout)
                {
                    // 修改标题

                    string strText = m_strTitleText + " (" + Convert.ToString(nTimeLeft / 1000) + " 秒后本对话框会自动关闭)";

                    // 注意这里是多线程操作,需要间接调用
                    if (this.InvokeRequired == true)
                    {
                        Delegate_SetTitleText d = new Delegate_SetTitleText(SetTitleText);
                        try
                        {
                            this.Invoke(d, new object[] { strText });
                        }
                        catch (ObjectDisposedException)
                        {
                            return;
                        }
                    }
                    else
                    {
                        base.Text = strText;
                    }

                    if (nThisTime < nPerTime) // 最后一次已经作完
                    {
                        if (this.InvokeRequired == true)
                        {
                            Delegate_CloseWindow d = new Delegate_CloseWindow(CloseWindow);
                            this.Invoke(d);
                        }
                        else
                        {
                            this.Close();
                        }
                        this.DialogResult = System.Windows.Forms.DialogResult.Retry;
                        return;
                    }
                    nTimeLeft -= nPerTime;
                }
                else
                {
                    return;
                }
            }

        }
Esempio n. 3
0
        public void ThreadMain()
        {
            int nTimeLeft = m_nTimeOut;	// ʣ�µ�ʱ��

            WaitHandle[] events = new WaitHandle[1];

            events[0] = eventClose;

            if (m_nTimeOut == -1)
            {
                WaitHandle.WaitAny(events);
                return;
            }

            int nPerTime = 1000;

            while(true)
            {
                int nThisTime = Math.Min(nTimeLeft, nPerTime);

                int index = WaitHandle.WaitAny(events, nThisTime, false);

                if (index == WaitHandle.WaitTimeout)
                {
                    // �޸ı���

                    string strText = m_strTitleText + " (" + Convert.ToString(nTimeLeft/1000) + " ��󱾶Ի�����Զ��ر�)";

                    // ע�������Ƕ��̲߳�������Ҫ��ӵ���
                    if (this.InvokeRequired == true)
                    {
                        Delegate_SetTitleText d = new Delegate_SetTitleText(SetTitleText);
                        try
                        {
                            this.Invoke(d, new object[] { strText });
                        }
                        catch (ObjectDisposedException)
                        {
                            return;
                        }
                    }
                    else
                    {
                        base.Text = strText;
                    }

                    if (nThisTime < nPerTime) // ���һ���Ѿ�����
                    {
                        if (this.InvokeRequired == true)
                        {
                            Delegate_CloseWindow d = new Delegate_CloseWindow(CloseWindow);
                            this.Invoke(d);
                        }
                        else
                        {
                            this.Close();
                        }
                        this.DialogResult = System.Windows.Forms.DialogResult.Retry;
                        return;
                    }
                    nTimeLeft -= nPerTime;
                }
                else
                {
                    return;
                }
            }
        }