在程序上导入一个大的txt文件 [英] import a big txt file on program

查看:52
本文介绍了在程序上导入一个大的txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个需要导入大型txt文件的程序,我使用了大小为100mb的txt文件和400万行,当我导入它并开始对其进行操作时,该程序使应用程序崩溃并需要重新启动程序,错误名称是程序已停止工作且问题代码是CLR20r3,我希望你们可以通过此指导我.

i am making a program that requires importing large txt files , i used a txt file 100mb in size and 4 million lines , when i import it and start operating on it , the program makes an application Crash and requires a restart of program , the error name is program has stopped working and problem code is CLR20r3 , i was hopefully you guys guide me through this .

推荐答案

您的问题是控件只能从GUI线程访问. Google Control.Invoke,您会找到必要的信息.

问候,

MRB
Your problem is that controls can only be accessed from the GUI thread. Google Control.Invoke and you will find the nescessary information.

Regards,

MRB


有关Manfred的基本正确解决方案的详细信息:

您无法从非UI线程调用与UI相关的任何操作.相反,您需要使用System.Windows.Threading.DispatcherInvokeBeginInvoke方法(对于Forms或WPF)或System.Windows.Forms.Control(仅对于Forms).

在我过去的答案中,您将找到有关其工作原理的详细说明和代码示例:
Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview Scanner和MD5的问题 [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

—SA
More detail on basically correct solution by Manfred:

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


使用调试器查找问题...并确保您打破所有异常.

对于此类大文件,您可能必须正确设计程序以处理大文件.根据您对文本所做的操作,可能会占用过多的内存.

您在导入时是否查看了程序的内存使用情况.
Uses the debugger to find the problem... and ensure that you break on all exceptions.

For such large files, you might have to properly design your program to handle large files. Depending on what you do with the text, it might take too much memory.

Have you look at the memory usage of your program while importing.


这篇关于在程序上导入一个大的txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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