Do not force it, because it more like to "End task". The file being used means, that the process "Web Dev Server" is relying on this file as some of the components may be using the data provided in that file. If you force delete that file, the process would be terminated and your website would face a downtime.
To overcome this, "
safely" close the process that is using it. You can use another interface or an object, that does that for you when you want to. What I mean by safely is, that your process saves the state, saves the data to the disk, ends itself in a manner that your server doesn't get halted or your website doesn't face a downtime.
A good solution to such problems is to release the resources that you are using. You may be using a
Stream
(
FileStream
specifically) to that file which is provided to your process, and you forgot to release the stream. Always remember to release the resources before terminating the processes as it leads to
memory leak[
^]. This case of yours, is a result of memory leak or a process using the file. If the case is "process currently using the file" then it can be closed, and resource can be released, in worse cases such as when the process is terminated but the resource wasn't released. Your file is going to remain open, and you would have to restart the machine.
In most of these cases,
using
[
^] statement helps you release the resources automatically. I would also like to recommend using this, in your application.
Understanding the 'using' statement in C#[
^]
Only then, you will be able to delete the files in a "good manner". Now of course you can just manually delete the file, let the process crash, make the website face a downtime and get your users annoyed at your 503 messages. But, that is not a good way of doing it, is it? Even replacing the file won't be done as long as the file is being used. So your process has to stop, wait until the file is refreshed, then start once again.