Skip to content

[ERROR] File Occupation Exception #99

@JusterZhu

Description

@JusterZhu

Component Version

9.5.10

Operating System Version

All

CPU Instruction Set Architecture

All

Error Description

In BinaryHandler.cs (within the Dirty method):
If we replace the original code block:

if (File.Exists(_oldfilePath))
{
    File.SetAttributes(_oldfilePath, FileAttributes.Normal);
    File.Delete(_oldfilePath);
}

if (File.Exists(_newfilePath))
{
    File.SetAttributes(_newfilePath, FileAttributes.Normal);
    File.Copy(_newfilePath, _oldfilePath, true);
}

with:

File.SetAttributes(_oldfilePath, FileAttributes.Normal);
File.Delete(_oldfilePath);
File.Move(_newfilePath, _oldfilePath);

The code works normally sometimes, but occasionally throws a "file is occupied" exception — even though the file has actually been deleted. This issue is particularly prominent when the main program shuts down abnormally.
Although File.Exists(_oldfile) returns false (meaning the file does not exist), the system still reports "file is occupied" due to multi-threading reasons.
When the Move operation fails, I replaced it with File.Copy(xx, xx, true) for testing, and this solution works.

Hardware Driver Update

No response

Error Sample Code Repository URL

No response

Sub-issues

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions