我新写了一个form来作为等待提示框,在查询统计中让它显示。
现在显示是可以显示了,我在等待提示框中加入的一个定时器来控制一个progressBar自动滚动,正常统计过程中progressBar不会自动走,这是什么原因?
统计过程中如果出错,progressBar则会自动走。//等待提示框类
    public partial class 状态提示 : BaseImeForm
    {
        private int iTime = 0;//用于时间
        private bool bAutoClose = false;//是否自动关闭        public 状态提示(bool b, int i)
        {
            InitializeComponent();            bAutoClose = b;
            iTime = i;
        }        //定时器
        private void timer1_Tick(object sender, EventArgs e)
        {
            int j = iTime / 20;
            progressBar1.PerformStep();            //自动关闭判断
            if (bAutoClose)
            {
                if (progressBar1.Value >= 200)
                    this.Close();
            }
            else
            {
                if (progressBar1.Value >= 200)
                    progressBar1.Value = 0;
            }
        }
    }//公用函数
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="bAutoClose">是否自动关闭,为true则自动关闭</param>
        /// <param name="nTime">如果是自动关闭,显示的时间</param>
        public static void ShowMsg(bool bAutoClose, int iTime)
        {
            if (m_FormMsg != null)
            {
                m_FormMsg.Close();
                m_FormMsg = null;
            }            m_FormMsg = new 状态提示(bAutoClose, iTime);
            m_FormMsg.Show();
        }        /// <summary>
        /// 关闭信息显示窗口
        /// </summary>
        public static void CloseMsg()
        {
            if (m_FormMsg != null)
            {
                m_FormMsg.Close();
            }            m_FormMsg = null;
        }
    }
//程序调用
            BaseDataOperate.ShowMsg(false, 0);
            Application.DoEvents();            //查询统计处理            BaseDataOperate.CloseMsg();

解决方案 »

  1.   

    像这种问题要用异步来处理,在异步处理过程中Timer是可以执行的,当异步执行完成了把Timer关闭等等因为你的程序是同步的在查询统计没有完成前程序的其它线程都处理于等待这个查询统计完成后才执行,因此你的Timer也是在等查询统计完成后才执行就不能达到你要的效果了.
      

  2.   

    例如如下的代码就是用异步来执行的:
    delegate object dlExecuteQuery();
    private void button1_Click(object sender, EventArgs e)
    {
    dlExecuteQuery de=new dlExecuteQuery(this.Query());
    IAsyncResult ir = de.BeginInvoke(null, null); Form f=new Form()
             f.ShowDialog(this);
    Application.DoEvents();
    while (!ir.IsCompleted)
    {
    Application.DoEvents();
    }
    object obj = de.EndInvoke(ir);
    f.Close();
    }private object Query()
    {
    //长时间的操作
    }
      

  3.   

    恩。用异步,begininvoke长时间操作,然后同时显示等待窗体
      

  4.   

    dlExecuteQuery de=new dlExecuteQuery(this.Query());这句出错,说应输入方法名称,我已经定义Query了。
      

  5.   

    .net编程方面的技术问题, 请加20962976, 有技术牛人, 会给您满意的答复