BR throws an error. The process cannot access the file because it is being used by another process.

OS_Pizza
Contributor III

I am getting an error while trying to access the file from the BR .

The process cannot access the file '\\XXXXXX.file.core.windows.net\onestreamshareprd1\FileShare\Applications\XXXXXXX\Groups\Everyone\XXXXXX\File_XXXXX.zip' because it is being used by another process.

4 REPLIES 4

ChristianW
Valued Contributor

If you access a file from a business rule, you first need open the file, than you do your activity, and then you close it. This is VB.net standard. If you open the file, but not close it, an error message like yours appears.

A common reason for open files is an error during the runtime, so that you opened the file but never succeed closing it. To avoid such a situation, you can use the try error handling to close the file even after running in a bug.

Oscar
Contributor

I am getting the same error when trying to write to a file ... I think it's due to multithreading

Dim oFile As StreamWriter =  New StreamWriter(BRAPi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.ApplicationIncoming, Nothing).Replace("\Incoming","\Groups\Everyone\test1.txt"),True)

oFile.WriteLine( api.Pov.Time.Name & " | " & api.Pov.Entity.Name & " | " & dataBuffSource.DataBufferCells.Count & " | " & elapsedTime )

oFile.Close

ChristianW
Valued Contributor

Probably. There are asynchronous versions of Write and WriteLine: WriteAsync and WriteLineAsync. But didn‘t tried it yet, so I don‘t know details.

Oscar
Contributor

Thank You Chrsitian for the reply! I will look into those two methods for my business rule