Synchronised image reading in multithreaded application

Hi. I opened a ticket via our paid support (#177178), but during that investigation, a new issue surfaced. Unfortunately, we’ve used our quota for support tickets, and I was requested to submit the issue here.

The issue is around the loading of Bitmaps in a multi-threaded application. In ticket 177178, I provide a sample project that repos this issue.

A brief explanation of the program is as follows. I implement my own FileStream and MemoryStream (we only use one at a time, but it proves the issue exists regardless of the stream type). I implement the Read method and log when a read occurs and for what file.

The program creates N threads and synchronises them with a reset event. Each thread retrieves a stream from a thread safe collection and attempts to create a bitmap from it. Examining the log outputs shows that Bitmap performs small reads of the stream to determine the format. These small reads are done synchronously, as you can see multiple reads for image1, then the same for image2 and the Nth image.

Once these reads are completed, the bigger reads of the pixel data are done async. This is a performance issue for us, and potentially a wider issue of locking up the other threads if the stream is slow/stalls.

I can provide the code/examples if you are unable to access them. Thanks!


Both normal (free) support and paid support help desks are different modules. We would appreciate it if you could create and provide a standalone sample application (complete source code without any compilation errors) to reproduce the performance issue you mentioned. We will evaluate your issue and assist you accordingly.

PS. Please zip the project with all the files prior to attaching them here.

Ah, I now see the upload button. Please let me know if there is anything I can do to help.

In the CustomFileStream and CustomMemoryStream, you’ll see i’ve added a 5 second sleep to simulate a slow read/lock that causes the other threads to pause processing. If you comment that out, you can see the synchronous reads.

The compilation folder will contain a output log file that shows the synchronicity of the reads.

Thanks! (6.6 MB)

When I was creating the topic, I could seem to find an obvious way to attach the code sample. I hope that attaching it to this email works!

Let me know if I can help!

image001.jpg (1.04 KB) (6.58 MB)


Thanks for providing us sample project and details.

We need to evaluate the issue with synchronized image reading in multithreaded application as you pointed. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DRAWINGNET-1444

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.


We 've tested your project with Aspose.Drawing.Common 23.10, System.Drawing.Common 6.0.0 and Aspose.Drawing.Common 23.11. We get minimal time and total execution time doesn’t indicate any multi-threaded problems.

With Aspose.Drawing.Common 23.11, the program is no longer stuck on waiting for the first thread to complete. We encourage you to retest with Aspose.Drawing.Common 23.11 to confirm that it fixes the problem or not?