Quantcast
Channel: Aspose.Email Product Family
Viewing all articles
Browse latest Browse all 1367

Is creating PST files in parallel supported?

$
0
0
Hi guys,

I'm trying to implement class which will be able create PST file from collection of MSG files. I would like to us the parallelism here but I don't know if this is even possible. Without parallelism my code works fine. I want to support something like this:

// run creating of several PST files in parallel
var testFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.msg");

IPSTParser parser = new PSTParser();
Parallel.For(1, 11, i =>
{
        var testPstFile = Path.Combine(Directory.GetCurrentDirectory(), string.Format("WritePSTFileFromMSGFilesTest_{0}.pst", 1));

         parser.WriteMSGFilesToPST(testFiles, testPstFile);
});

// and inside the parser class use parallel to write MSG files into PST
using (var storage = GetOrCreatePSTStorage(pstFile))
{
        // Select the "Inbox" folder
        var inboxFolder = storage.RootFolder.GetSubFolder("Inbox");
        Parallel.ForEach(messageFiles, message =>
        {
                if (File.Exists(message))
                {
                         // Add some messages to "Inbox" folder
                        inboxFolder.AddMessage(MapiMessage.FromFile(message));
                 }
        });
}

Sometimes it really does create few PST files (e.g. 5 of 10 expected) without crashing. But most of the times it starts with creating several PST files but crashes on some exception like:

An exception of type 'System.Exception' occurred in Aspose.Email.dll but was not handled in user code
Additional information: Page data is not valid.

An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code
Additional information: An attempt was made to move the file pointer before the beginning of the file.

and other.. 
The last one can be related to reading MSG files which in my case wont't be the case in production so I can lock this files. Anyway I tried to lock currently accessing MSG file and then another exception appears:

An exception of type 'System.ArgumentOutOfRangeException' occurred in Aspose.Email.dll but was not handled in user code
Additional information: Non-negative number required.

Can someone please help me if this use case is supported and how can I ensure it will work without any exceptions?

Thanks a lot!
Marek

Viewing all articles
Browse latest Browse all 1367