Archived Forum Post

Index of archived forum posts

Question:

C# htmltoxml and mulitthreading throughput problem?

Jul 06 '12 at 09:20

I am having some trouble with multithreading and throughput.

private static Chilkat.HtmlToXml[] h2xml = new Chilkat.HtmlToXml[64];

later in my code . . .

    DoWorkEventHandler getSellerIPD = (sender, e) =>
    {
    h2xml[threadIdx] = new Chilkat.HtmlToXml();
    Chilkat.HtmlToXml h2xfile = new Chilkat.HtmlToXml();

. . .

    strHTMLary[threadIdx] = h2xfile.ReadFileToString(fn, "utf-8");
    h2xml[threadIdx].Html = strHTMLary[threadIdx];
    strXMLary[threadIdx] = h2xml[threadIdx].ToXml();
    }

The above is just a portion of the code I am dealing with, but after much testing, everything performs as expected except the .ToXml(). It performs very slowly compared to its single threaded equivalent. The elapsed time for a single thread (i.e., threadIdx=0) is roughly the same as when having 4 threads. In other words, if I comment out the line with the .ToXml(), multithreading gives me the throughput I am looking for.

Is .ToXml() thread safe? Is the above legal/supported? Any thoughts on this is appreciated.


Answer

After reviewing the internal Chilkat source, I think I see the problem and it has to do with the multi-thread safety. These new builds should fix it:

2.0/3.5 Framework:

32-bit: http://www.chilkatsoft.com/preRelease/ChilkatDotNet2.zip
64-bit: http://www.chilkatsoft.com/preRelease/ChilkatDotNet2_x64.zip

4.0 Framework:

32-bit: http://www.chilkatsoft.com/preRelease/ChilkatDotNet4.zip
64-bit: http://www.chilkatsoft.com/preRelease/ChilkatDotNet4_x64.zip