I have this error since today in a project which I have worked for months and has always worked.
I tried cleaning the solution and rebuild, and building works perfect. I
I wanted to share my scenario here if it helps someone. I set an interval in javascript for two different functions calling the same function on the server side each differentiated with a just one parameter. Then OS threw the above error
The process cannot access the file because it is being used by another process
[WebMethod]
public List<Notifications> GetNotifications()
{
return objCommonModels.GetNotificationsData(1);
}
[WebMethod]
public List<Notifications> GetOTPNotifications()
{
return objCommonModels.GetNotificationsData(2);
}
//Javascript
setInterval(LoadNotifications, 3000);
setInterval(LoadOTPNotifications, 3000);
Then i seperated the two functions to make them unique... I didn't have faith in differentiating the timer seconds in JS... HOPE IT HELPS SOMEONE..
As the message says, the file is in use. This isn't a Visual Studio or .NET thing, it is an operating system thing.
Another program is using the file, that can be a virus scanner, another application that is running, or even Visual Studio (sometimes the debugger keeps a file locked).
Windows tells you what program is responsible for the lock when you try to delete or rename the file. I would recommend to do that to see what program is locking your file.
Another scenario where you will see the 'in use by another program' error is when you try to enable or create Entity Framework migrations, while you did not build your project after you made changes to models or a database context.
Just build the solution and the error goes away.