[Html2PdfConverter] The process cannot access the file '...'because it is being used by another process.

[Html2PdfConverter] The process cannot access the file '...'because it is being used by another process.

  
Forge Component
(42)
Published on 23 Jun by Guilherme Pereira
42 votes
Published on 23 Jun by Guilherme Pereira

We are generating some pdf files using an asynchronous process.

If randomly fails some of the processes with the message:

The process cannot access the file 'D:\TEMP\TEMPBEMYMKMCTS00000000000000000000000000000000.pdf' because it is being used by another process.

It would seem that it only happens when i do it for multiple pdf's at the same time.

Anyone had the same problem?

According to the code in the extension the tempfile is created using the Random(int32) function were you put in a seednumber based upon the systemtime. Because the asynchronous processes can run at the same time it will result in an equal number.

Some solutions found on the net uses cpu thread aware functions or GUID.

I used the GUID input so the function looks like this:

OLD: Random rnd = new Random((int)System.DateTime.Now.Ticks);

NEW: Random rnd = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));

Now we don't have any problems when running multiple processes at the same time.

I don't know if there is any penalty when using this function but I hope you can change this in a new version so we can keep using the new updates of very nice module in the future !!!!



Does anyone know if this change is already merge in the "production" version?

We want to be on par with the forge version so we are upgrade proof...