Can't delete png.file because it is in use by other processes

Hey Community,

I installed the method from this topic into my robot to adjust the image size. Since I want to use the newly generated image and not the old one, I try to delete it using the delete-activity. However, I get the message: The process cannot access the file because it is being used by another process.

The deletion does not take place immediately but much later. I still get this message. Can it be that the image remains open in the “invoke Method method” or via “system.Drawing.Image.FromFile”? I can’t explain it at all and I hope that you can help me in this matter.

thanks in advance and best regards

Can you show me code or file so i can see what you are doing and where you are facing issue.

Hi Raja,

here is the sequence:

It is the same sequence code from here

Later then i want to delete the old one:

I can only delete it when the robot stops working.

Nobody can help?

@aytac22 first of all sorry for late reply …yesterday I was not online.
Can you run in debug mode and point out where you are facing issue

1 Like

Hello @aytac22
Try this, it may helps you
Kindly use For Each File in Folder activity and use the Delete File activity in the loop
Use “.png” in filter

1 Like

Run the resizing procerure as a separate workflow (using InvokeWorkflow) with “Isolate” option ON.


1 Like

Seems to be a lot of issues lately where activities don’t let go of the file like they should. Put this right before you try to delete the file, to force it to “let go”:


The second one is WaitForPendingFinalizers


Good trick! It works

1 Like

Please mark as solution

1 Like

Good morning people.

First of all, thanks for the help and tips. I’m also sorry for only now replying. I was on vacation.

I looked at the tips and tried the last one from paul postwick and also from Gokul Jai. However, I do not get the screenshot deleted because it is still being used by the system.

I posted my sequence again. it’s just the one sequence. I get the error message at the end when deleting. What am I doing wrong?

It stops here:

With the Error-Message as i said:

Quelle: Delete

Meldung: Der Prozess kann nicht auf die Datei “C:\Users\Public\Documents\Screenshot.png” zugreifen, da sie von einem anderen Prozess verwendet wird.

Ausnahmetyp: System.IO.IOException

RemoteException wrapping System.IO.IOException: Der Prozess kann nicht auf die Datei “C:\Users\Public\Documents\Screenshot.png” zugreifen, da sie von einem anderen Prozess verwendet wird.
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.File.InternalDelete(String path, Boolean checkHost)
bei System.IO.File.Delete(String path)
bei UiPath.Core.Activities.Delete.Execute(CodeActivityContext context)
bei System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
bei System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
bei System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

The Message is in german and means: The process cannot access the file “C:\Users\Public\Documents\Screenshot.png” because it is being used by another process.

Hello Raja,

is done. Look at my post. Thank you very much.

ok, the problem was that after i opened the Image, it was locked accordingly. the picture must therefore be approved or disposed (see here).

So i did this:

Ater then the invoke methods ensure that the cache is emptied.

Thank you very much for your help guys.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.