数据网格视图需要很长时间才能更新 [英] Data Grid View Taking long time to update

查看:69
本文介绍了数据网格视图需要很长时间才能更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



以下代码工作正常,但需要很长时间。我相信它不是网络速度。你能帮忙吗?



  Dim  i  As  整数 =  0  
Dim BatchNumber As String

< span class =code-comment>' 目标目录
Dim 目录= \\fppdszv03\GPM-QM \ PROD\Indigo5500 C:\ Users \Shafiul Alam \Desktop \ Hot Folder

对于 i = 0 dgv.Rows .Count - 1

BatchNumber = dgv.Rows(i).Cells( 0 )。值& * .mjm
For 每个文件名作为 字符串 IO.Directory.GetFiles(目录,BatchNumber,IO.SearchOption.AllDirectories)

dgv.Rows(i).Cells( 5 )。值= 搜索..
' 下一行代码只从搜索到的目录和子目录中获取文件扩展名
< span class =code-keyword> Dim fName As String = filename ' IO.Path.GetExtension(filename)
Dim FileInfo As FileInfo(filename)

dgv.Rows(i).Cells( 6 )。Value = FileInfo.Name
dgv.Rows(i).Cells( 7 )。Value = filename
dgv.Rows(i).Cells( 5 )。值= 找到文件
' Label6.Text = Label6.Text + 1
dgv.Rows(i).Cells( 8 )。值= C:\ Users \Shafiul Alam \Desktop\DFE \ & FileInfo.Name
File.Copy(dgv.Rows(i).Cells( 7 )。Value,dgv.Rows(i).Cells( 8 )。值)
dgv.Rows(i).Cells( 5 )。Value = < span class =code-string> 发送给DFE
' Label7.Text = Label7.Text + 1
dgv.Rows(i).Cells( 5 )。Style.BackColor = Color.DarkGreen
下一步
下一步

解决方案

首先,看一下你的目录:由于GetFiles调用正在返回这个和所有子目录中的所有文件,可能需要一些返回时间相当长,因为文件系统已经抓取了整个结构。



其次,看看你在里面做了什么内部循环 - 一遍又一遍地更新相同的单元格。



记住,你是在UI线程的循环内执行此操作 - 所以很有可能目录搜索无论如何阻止任何更新。



我会考虑将代码移到BackgroundWorker中,并通过Progress报告为行发出更新。

Dear All,

Below code is working fine, but takes long time. Its not the network speed, I believe. Can you please help?

Dim i As Integer = 0
       Dim BatchNumber As String

       'Target Directory
       Dim directory = "\\fppdszv03\GPM-QM\PROD\Indigo5500" '     C:\Users\Shafiul Alam\Desktop\Hot Folder

       For i = 0 To dgv.Rows.Count - 1

           BatchNumber = dgv.Rows(i).Cells(0).Value & "*.mjm"
           For Each filename As String In IO.Directory.GetFiles(directory, BatchNumber, IO.SearchOption.AllDirectories)

               dgv.Rows(i).Cells(5).Value = "Searching.."
               'The next line of code gets only file extensions from searched directories and subdirectories
               Dim fName As String = filename 'IO.Path.GetExtension(filename)
               Dim FileInfo As New FileInfo(filename)

               dgv.Rows(i).Cells(6).Value = FileInfo.Name
               dgv.Rows(i).Cells(7).Value = filename
               dgv.Rows(i).Cells(5).Value = "File Found"
               'Label6.Text = Label6.Text + 1
               dgv.Rows(i).Cells(8).Value = "C:\Users\Shafiul Alam\Desktop\DFE\" & FileInfo.Name
               File.Copy(dgv.Rows(i).Cells(7).Value, dgv.Rows(i).Cells(8).Value)
               dgv.Rows(i).Cells(5).Value = "Send to DFE"
               'Label7.Text = Label7.Text + 1
               dgv.Rows(i).Cells(5).Style.BackColor = Color.DarkGreen
           Next
       Next

解决方案

Firstly, take a look at your directory: since the GetFiles call is returning all files in this and all subdirectories, it may take some considerable time to return, as the file system has crawl the entire structure.

Secondly, look at what you are doing inside the inner loop - updating the same cells over and over again.

Remember, you are doing this inside a loop on the UI thread - so there is a good chance that the directory search is blocking any updates anyway.

I'd consider moving the code into a BackgroundWorker, and issuing an "update" for a row via a Progress report.


这篇关于数据网格视图需要很长时间才能更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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