【问题标题】:Data Virtualization to handle text file处理文本文件的数据虚拟化
【发布时间】:2013-08-12 21:55:06
【问题描述】:

我读了这个链接:

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);

                }
            }
           }

文本大小为 2 mb,但启动数据虚拟化时,它使用 3 gig 内存!

我想知道如何使用数据虚拟化来读取文本文件?

【问题讨论】:

    标签: c# wpf winforms


    【解决方案1】:

    由于您正在阅读整个文本文件,因此您违背了数据虚拟化的目的,即延迟加载数据的可见部分。为此,您需要一个具有固定记录大小的数据库或文件,并且您可以从中读取与 UI 中显示的部分相对应的数据子集。请仔细阅读这篇文章以了解它需要什么。此外,如果您只处理 2MB 的数据,请避免不必要的复杂性。不要用大锤敲碎螺母。

    作为对您的评论的跟进,让我为您提供以下提示: 您正在重复读取文件并获得文件中的计数 × 记录数。 每次滚动时都会执行您的代码。从那里获取并开始相应地修改您的代码。

    【讨论】:

    • 感谢您的回答,但 2 mb 文本文件是示例,我想查看大约 1 gig 的大文本文件。那么你能用代码示例解释更多以帮助我正确的方式吗?先谢谢了。我也找到了这个链接:stackoverflow.com/questions/3427600/…,他们提到过,但我需要你的帮助来解决这个问题。
    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多