| |

VerySource

 Forgot password?
 Register
Search
View: 951|Reply: 4

Urgent use of FileSystemWatcher to monitor folder changes

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-10 11:30:01
| Show all posts |Read mode
I use FileSystemWatcher to monitor a folder of the machine. When a new file appears, I move the file to another folder. I use the create event to trigger it, but sometimes an error occurs when moving the file , It prompts that the file is being used by other processes. I don’t know what causes it. What is the solution.
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-11-10 11:45:01
| Show all posts
This is because the user may copy files to this folder, and it takes a long time to copy files!
There is no complete plan (personal opinion)
You can set a time interval and then transfer!
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-10 15:45:22
| Show all posts
But there is no problem when I move files into the folder or cut files into it.   When copying files to the folder, there is a problem that the files are occupied by other processes.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-11-10 17:15:01
| Show all posts
to I use the create event to trigger, but sometimes an error occurs when moving a file, saying that the file is being used by another process. I don’t know what caused it. What is the solution.

You can use an exclusive way to see if you can open the file, and then move it if you can.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-10 18:00:01
| Show all posts
The reasons are as follows:

Created-Submit this event when a new file is created in the monitored directory. If you plan to use this event to move the newly created event, you must write some error handling code in the event handler, which can handle the current file being used by other processes. The reason for this is that the Created event may be submitted before the file creation process releases the file. If you do not have the code to handle this situation correctly, an exception may occur.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list