简体   繁体   English

快速清理数据集 - 读取 xml 文件 (C#)

[英]Fast cleaning DataSet - reading xml files (C#)

I use a DataGrid to show a xml file.我使用 DataGrid 来显示一个 xml 文件。 The Grid's DataSource is a DataSet.(using schema) Grid 的 DataSource 是一个 DataSet。(使用架构)

            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream("XML_Reader.Resources.schema.xsd");
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(null, XmlReader.Create(stream));
            using (XmlReader reader = XmlReader.Create(xmlFile, settings))
            {
                newDataSet.ReadXml(reader);
            }
            dataGrid.DataSource = newDataSet;


But when reading a new xml file, i need to clear the DataSet.( newDataSet.Clear(); )但是在读取新的 xml 文件时,我需要清除 DataSet.( newDataSet.Clear(); )
Because i read 'large' (40 Mb) xml files, clearing the DataSet is very slow.因为我读取了“大”(40 Mb)xml 文件,所以清除数据集非常慢。

How can i speed up this clearing?我怎样才能加快这个清算?
Reading the file is also slow !读取文件也很慢!

On a: Intel i7 950, 8 Gb, Win7 64-bit.在一个:英特尔 i7 950,8 Gb,Win7 64 位。

Why can't you just create new dataset and use that instead clearing old one?为什么不能创建新数据集并使用它来清除旧数据集? The old one will be garbage collected by .NET.旧的将被 .NET 垃圾收集。

I suggest you use a new DataSet object for each file and avoid using DataSet.Clear() altogether.我建议您为每个文件使用一个新的DataSet对象,并避免完全使用DataSet.Clear() Just leave the old datasets to be cleared up by the garbage collector.只需让垃圾收集器清除旧数据集即可。

Let me answer my own question ;-))让我回答我自己的问题;-))

A typed DataSet is simply a class you can instantiate like any other class.类型化 DataSet 只是一个可以像任何其他类一样实例化的类。
There is no magic to anything generated by tools, those tools simply generate classes and you can use those classes the same way you use other classes.工具生成的任何东西都没有魔法,这些工具只是生成类,您可以像使用其他类一样使用这些类。

Do NewDataSet d1 = new NewDataSet();NewDataSet d1 = new NewDataSet(); where you put the right class name there instead of "NewDataSet".在那里放置正确的类名而不是“NewDataSet”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM