读取多线程的xml文件 [英] Reading a xml file multithreaded

查看:196
本文介绍了读取多线程的xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了很多搜索,但找不到适合我问题的合适解决方案.我写了一个xml文件,其中包含电视节目的所有剧集信息.它为38 kb,包含约680个变量的属性和字符串.最初,我只是在XMLTextReader的帮助下简单地阅读了该文档,该文档在我的四核处理器上运行良好.但是我妻子五岁的笔记本电脑花了大约30秒钟来阅读它.所以我想到了多线程,但由于文件已经打开而出现了异常.

I've searched a lot but I couldn't find a propper solution for my problem. I wrote a xml file containing all episode information of a TV-Show. It's 38 kb and contains attributes and strings for about 680 variables. At first I simply read it with the help of XMLTextReader which worked fine with my quadcore. But my wifes five year old laptop took about 30 seconds to read it. So I thought about multithreading but I get an exception because the file is already opened.

线程启动看起来像这样

while (reader.Read())
{
   ...
   else if (reader.NodeType == XmlNodeType.Element)
   {
       if (reader.Name.Equals("Season1"))
       {
           current.seasonNr = 0;
           current.currentSeason = season[0];
           current.reader = reader;
           seasonThread[0].Start(current);
       }
       else if (reader.Name.Equals("Season2"))
       {
           current.seasonNr = 1;
           current.currentSeason = season[1];
           current.reader = reader;
           seasonThread[1].Start(current);
       }

还有这样的解析方法

reader.Read();

for (episodeNr = 0; episodeNr < tmp.currentSeason.episode.Length; episodeNr++)
{
    reader.MoveToFirstAttribute();
    tmp.currentSeason.episode[episodeNr].id = reader.ReadContentAsInt();
    ...
}

但这不起作用...

我通过阅读器是因为我希望光标"处于正确的位置.但是我也不知道这是否可行.

I pass the reader because I want the 'cursor' to be in the right position. But I also have no clue if this could work at all.

请帮助!

伙计们,我在哪里写有关IE的信息?我编写的程序解析该文件.我在PC和笔记本电脑上运行它.根本没有IE.

Guys where did I wrote about IE?? The program I wrote parses the file. I run it on my PC and on the laptop. No IE at all.

我进行了一些秒表研究,发现解析xml文件在我的PC上仅花费200毫秒,而在妻子的笔记本电脑上仅花费800毫秒. WPF的声音这么慢吗?我该怎么办?

I did some stopwatch research and figured out that parsing the xml file only takes about 200ms on my PC and 800ms on my wifes laptop. Is it WPF beeing so slow? What can I do?

推荐答案

我同意大多数人的意见.读取38Kb文件应该不需要很长时间.您是否还在计算机,防病毒软件等上运行其他东西,可能会干扰处理?

I agree with most everyone's comments. Reading a 38Kb file should not take so long. Do you have something else running on the machine, antivirus / etc, that could be interfering with the processing?

创建线程所花费的时间将远远大于读取文件所花费的时间.如果您可以发布用于读取文件和文件本身的实际代码,则可能有助于分析性能瓶颈.

The amount of time it would take you to create a thread will be far greater than the amount of time spent reading the file. If you could post the actual code used to read the file and the file itself, it might help analyze performance bottlenecks.

这篇关于读取多线程的xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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