c#计时器与文件计数器

1、前几天,因业务需求,需要知道导出数据执行一次所花的时间,监测导出数据文件夹文件个数,是否还有文件在导出
2、想到了c#中的计数器和计时器
计时器部分代码如下

private void timer1_Tick(object sender, EventArgs e)
        {
            _nowSecond++;
            int hour = _nowSecond / 3600;
            labelHour.Text = hour.ToString();
            int minute = (_nowSecond /60) ;
            labelMinute.Text = minute.ToString();
            double second = _nowSecond % 60 ;
            labelSecond.Text = second.ToString();
            btnFileCount.Text = GetFilesCount(dirInfo).ToString();
        }

统计文件个数计数器代码如下

    public static int GetFilesCount(System.IO.DirectoryInfo dirInfo)
        {
            int totalFile = 0;
            totalFile += dirInfo.GetFiles().Length;
            foreach (System.IO.DirectoryInfo subdir in dirInfo.GetDirectories())
            {
                totalFile += GetFilesCount(subdir);
            }
            return totalFile;
        }

代码工程文件下载地址:
https://github.com/knowledge0603/timer

猜你喜欢

转载自blog.csdn.net/guoruijun_2012_4/article/details/80676968