如何尽可能快地显示大文件 [英] How to display a big file as fast as possible

查看:104
本文介绍了如何尽可能快地显示大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个FileReader,它以DragEnter和DragDrop的形式显示文件的内容.问题发生了.将内容从文件加载到内存需要花费一些时间,但是当我将内容显示到文件时标签上标有"XXXX.text = FileContent"之类的代码,这花了我超过5分钟的时间.
有人可以帮助我吗?


下面的代码:
私有Sub rtbContent_DragDrop(ByVal发送者作为System.Object,ByVal e作为DragEventArgs)处理rtbContent.DragDrop
试试
昏暗的sPath()作为字符串

sPath = e.Data.GetData(DataFormats.FileDrop)

如果sPath什么都没有,那么
''rtbContent.LoadFile(sPath(0),RichTextBoxStreamType.PlainText)
stopWatcher.Start()
昏暗的字符串作为字符串= My.Computer.FileSystem.ReadAllText(sPath(0))
stopWatcher.Stop()
rtbContent.Text + ="ReadALLText:"& stopWatcher.Elapsed.Milliseconds& "
stopWatcher.Reset()


''stopWatcher.Start()
''rtbContent.Text =字符串
''stopWatcher.Stop()
" rtbContent.Text + ="DisplayIt:"& stopWatcher.Seconds& stopWatcher.Elapsed.Milliseconds& "
''stopWatcher.Reset()
其他
MessageBox.Show(sMessageFailure)
如果结束
异常捕获

结束尝试
结束子

I was design a FileReader which displays the Content of the file in the form of DragEnter and DragDrop.The problem has occured.it tooks a bit of time to load the content from file to memory but when i display the content to the label with the codes like "XXXX.text=FileContent",it tooks me more than 5 mins.
Is anyone coule help me?


code below:
Private Sub rtbContent_DragDrop(ByVal sender As System.Object, ByVal e As DragEventArgs) Handles rtbContent.DragDrop
Try
Dim sPath() As String

sPath = e.Data.GetData(DataFormats.FileDrop)

If sPath IsNot Nothing Then
''rtbContent.LoadFile(sPath(0), RichTextBoxStreamType.PlainText)
stopWatcher.Start()
Dim strings As String = My.Computer.FileSystem.ReadAllText(sPath(0))
stopWatcher.Stop()
rtbContent.Text += "ReadALLText: " & stopWatcher.Elapsed.Milliseconds & " "
stopWatcher.Reset()


''stopWatcher.Start()
''rtbContent.Text = strings
''stopWatcher.Stop()
''rtbContent.Text += "DisplayIt: " & stopWatcher.Seconds & stopWatcher.Elapsed.Milliseconds & " "
''stopWatcher.Reset()
Else
MessageBox.Show(sMessageFailure)
End If
Catch ex As Exception

End Try
End Sub

the blocked code was the point

推荐答案

写道:​​

出现了问题.将内容从文件加载到内存需要花费一些时间,但是当我使用"XXXX.text = FileContent"之类的代码将内容显示到标签上时,花了我超过5分钟的时间.

The problem has occured.it tooks a bit of time to load the content from file to memory but when i display the content to the label with the codes like "XXXX.text=FileContent",it tooks me more than 5 mins.



如果文件太大以至于需要花费五分钟的时间来加载,为什么要在标签中全部显示呢?问题是代码的拖放部分吗?文件有多大?在我看来,您可能需要提供更多详细信息,或者您正在做的事情对我来说没有意义,但是如果需要那么长时间,您将不得不忍受.您的代码要么效率很低,要么就是要花多长时间.在看不到代码的情况下,我们无法分辨.



If the file is so big that it takes five minutes to load, why are you showing it all in a label ? Is the problem the drag and drop portion of the code ? How big is the file ? It seems likely to me that you either need to provide more details, or that you''re doing something that makes no sense to me, but which you''re going to have to live with, if it takes that long. Either your code is grossly inefficient, or that''s how long it takes. We can''t tell which, without seeing the code.


在禁用了自动换行并同时启用两个滚动条的TextBox中显示文本.这与您将要获得的速度一样快.

现在您已经添加了一些代码,我会说问题出在RichTextBox上.这是可用于显示文本的最重的控件之一.遵循我的上述建议,并尝试一下TextBox(设置了适当的属性).

出于好奇,文件有多大?

另外,您一次只需要显示部分文本.您可以创建一个自定义控件,将该文件用作磁盘阵列.该控件将只需要加载在任何给定点可见的文本.这将几乎立即加载.
Display the text in a TextBox that has word wrap disabled and both scroll bars enabled. That''s about as fast as you''re going to get.

Now that you have added some code, I would say the problem is with the RichTextBox. That is one of the most heavy-weight controls you can use to display text. Go with my above suggestion and give the TextBox a try (with the appropriate properties set).

Out of curiosity, how big is the file?

Also, you only need to display part of the text at a time. You could create a custom control that uses the file as an on-disk array. That control would only have to load the text that was visible at any given point. That would load almost instantly.


您将不得不通过查看滚动条位置来确定文本框的哪个部分可见.然后加载并仅显示文件的该部分.

您真的不必一次加载这么大的文件.
You''ll have to figure out which portion of the text box is visible by looking at the scroll bar position. Then load and display only that portion of the file.

You really don''t have to load such a huge file at once.


这篇关于如何尽可能快地显示大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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