在Windows应用程序中处理方法需要太多时间 [英] Method takes too much time to process in windows application

查看:64
本文介绍了在Windows应用程序中处理方法需要太多时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体,用于自动加载文件夹中的所有Excel文件。它有两个按钮启动和停止以及一个计时器。单击开始按钮时,该过程开始。问题是上传单个文件需要将近半个小时。过程太慢。每个excel文件有500-600行。请有人帮帮我。



我尝试过的事情:



I have a windows form for autouploading all excel files in a folder. It has two buttons start and stop and a timer. When the start button is clicked the process starts. The problem is that it takes nearly half an hour to upload a single file.The process is too slow .Each excel files has 500-600 rows. Can someone help me please.

What I have tried:

 private void strtbtn_Click(object sender, EventArgs e)
         {
             timer1.Enabled = true;
         }
<pre>private void timer1_Tick(object sender, EventArgs e)
         
{
             CallCustomer();
                CallCustomerError();
                lbl1.Text = "Process started.....";
                string source = "D:\\Excels";
                string destination = "D:\\Excelsuploaded";
                if (!(Directory.Exists(destination) && Directory.Exists(source)))
                    return;
                string[] Templateexcelfile = Directory.GetFiles(source);
                int filecount = Templateexcelfile.Length;
                foreach (string file in Templateexcelfile)
                {
                    uploadexcl(file);
                    lbl2.Text = counter.ToString();
                    counter = counter + 1;
                    fcount = fcount + 1;
                }
            }


<pre>

推荐答案

引用:

有人可以帮我吗。



基本上没有。问题是我们不知道您的 uploadexcl 方法正在做什么,但上传部分意味着涉及到互联网。你正在做的是一个接一个地向你的服务器发送一个串行文件流,如果上传占用整个互联网连接上传带宽,那么这个过程就不会加速了 - 就像默认情况下那样。上传速度通常很多,下载速度慢很多:下载速度为40Mbps,上传速度为8Mbps。如果您的Excel文件具有相当大的尺寸(并且这将取决于行和单元格数量以及单元格内容),那么它们可能会花费大量时间。

检查文件大小(以字节为单位),检查连接的上传速度,除以其他时间10(每字节8位,加上一些用于开销),你将获得秒数每个文件。然后使用Stopwatch类检查uploadexcl 对每个文件的持续时间。如果数字接近,除非通过改善您的互联网连接,否则无法加快处理速度。


Basically, no. The problem is that we have no idea what your uploadexcl method is doing, but the "upload" part implies the internet is involved. What you are doing is sending a serial stream of file to your server, one after the other, and that process can't be speeded up if the upload is taking the entire internet connection upload bandwidth - as it will by default. And upload speeds are normally a lot, lot slower that download: I get 40Mbps download, and 8Mbps upload. If your excel files are of a significant size (and that will depend on the row and cell count, as well as the cell content) then they could be taking a significant amount of time each.
Check the file sizes in bytes, check the upload speed of your connection, divide one by the other-times-10 (8 bits per byte, plus some for overhead) and you'll have the seconds per file. Then use the Stopwatch class to check how long uploadexcl takes for each file. If the numbers are close, you can't speed the process up except by improving your internet connection.


这篇关于在Windows应用程序中处理方法需要太多时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆