打印

[.Net] C#(C/S) 执行时间时间过长,界面白白一片,怎么处理

C#(C/S) 执行时间时间过长,界面白白一片,怎么处理

刚刚入手C/S程序
数据一次处理比较多,一次执行时间超过半小时,
执行的时候,就像WINDOWS下未响应的样子
怎么处理,怎么才能在界面显示进度
我大概知道应该是用进程处理,
所以大家不要光讲理论,贴点演示代码

TOP

C# codeThread th = new Thread(new ThreadStart(DataProcess));
th.Start();

TOP

你可以做个等待框
参考下BackGroundWorker

TOP

C# code
....
   step = quan / 5;
            sreach sr1 = new sreach(start, (start + step));
            start += step;
            sreach sr2 = new sreach(start, (start + step));
            start += step;
            sr1.thd.Join();
            sr2.thd.Join();
            sreached = sr1.userful + sr2.userful;
            label15.Text = sreached.ToString();
....




C# code
class sreach
    {
        public int start;
        public int end;
        public int userful;
        public Thread thd;
        public sreach(int s1, int e1)
        {
            userful = 0;
            start = s1;
            end = e1;
            thd = new Thread(this.run2);
            thd.Start();
        }

        void run2()
        {
            common comm = new common();
            string type = "";
            string description = "";
            DataSet ds = null;
            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                //这里放执行代码
            }
        }
    }

TOP

用delegate,委托的方法起一个线程专门查询数据库,查询完了回调到窗体中。其实就像是消息处理那样。
www.kooboy.net

TOP

google上搜索一下吧,很多例子的!
很高興認識從事SAP的朋友.... 讓我們一起學習,共同進步.... MSN:lgjxin@hotmail.com

TOP

多线程
Everything happens for a reason.

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-12-3 08:58 京ICP证060528 号

Designed By 17DST