我读到了这个链接:
http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization
要使用数据虚拟化读取文本文件:
在DemoCustomerProvider.cs中,我更改了:
for( int i=startIndex; i<startIndex+count; i++ )
{
Customer customer = new Customer { Id = i + 1, Name = "Customer" + (i+1) };
list.Add(customer);
}至:
for( int i=startIndex; i<startIndex+count; i++ )
{
using (StreamReader str = new StreamReader("C:\\test.txt"))
{
while (str.ReadLine() != null)
{
string data=str.ReadLine();
Customer customer = new Customer { Id = i + 1, Name =data }
list.Add(customer);
}
}
}文本大小是2MB,但当启动数据虚拟化时,它使用3G的内存!
我想知道如何使用数据虚拟化来读取文本文件?
发布于 2013-08-12 14:38:58
由于您正在读取整个文本文件,因此您违背了data Virtualization的目的,即只延迟加载数据的可见部分。要实现这一点,您需要一个具有固定记录大小的数据库或文件,您可以从中读取与UI中显示的部分对应的数据子集。请仔细阅读这篇文章,以了解它需要做些什么。此外,如果您只处理价值2MB的数据,请避免不必要的复杂性。不要用大锤子敲开螺母。
作为您的评论的后续内容,让我为您提供以下提示:您正在重复读取文件,并获得文件中的计数×记录数。每次滚动时,代码都会执行。从那里开始,开始相应地修改您的代码。
https://stackoverflow.com/questions/18180640
复制相似问题