Output file locked by another process when building
Asked Answered
M

2

4

I am using Visual Studio 2010 creating a XNA application with the Kinect SDK 1.6. I have a problem that the build usually fails (not always) after debugging the application. There is a process that is locking KinectDrobePrototype1.exe.

Error 12 Unable to copy file "obj\x86\Debug\KinectDrobePrototype1.exe" to 
"bin\x86\Debug\KinectDrobePrototype1.exe". The process cannot access the file
'bin\x86\Debug\KinectDrobePrototype1.exe' because it is being used by another
process.

Error 11 Could not copy "obj\x86\Debug\KinectDrobePrototype1.exe" to
"bin\x86\Debug\KinectDrobePrototype1.exe". Exceeded retry count of 10. Failed.  

I have used Process Explorer which tells me it is the System process.

Process  |  PID  |  Type  |  Name
System       4      File     C:\Users\ ... \KinectDrobePrototype1\KinectDrobePrototype1\KinectDrobePrototype1\bin\x86\Debug\KinectDrobePrototype1.exe

I have seen similar posts like this but it hasn't helped. I feel that there must be something in my application that still has a handle on something. I know for certain that when the application terminates the following code executes within my KinectManager class.

public void CleanUp()
{
    if (ActiveKinectDevice != null)
        UnintialiseDevice(ActiveKinectDevice);
}

private void UnintialiseDevice(KinectSensor device)
{
    device.Stop();

    device.ColorStream.Disable();
    _ColourPixelData = null;

    device.DepthStream.Disable();
    _DepthPixelData = null;

    device.SkeletonStream.Disable();
    _SkeletonData = null;
}

I am very new to XNA so it possible that there is something I have not done. On the UnloadContent I have the following:

protected override void UnloadContent()
{
    _KinectManager.CleanUp();
    _DrawingManager.CleanUp();           
}

And then in my DrawingManager class I dispose of the few textures I have used, my SpriteBatch and GraphicsDevice:

public void CleanUp()
{
    HandIcon.Dispose();
    JointIcon.Dispose();
    _ColourImage.Dispose();
    _DepthImage.Dispose();

    _SpriteBatch.Dispose();
    _GraphicsDevice.Dispose();           
}

Has anyone got any suggestions? Or is there an obvious mistake that I have made?

Edit 1: I forgot to mention that I am using the polling method for the Kinect, which is why I have not unregistered for any events.

Edit 2: For clarification, the System process does release the file eventually - it does not stay locked. I think this usually takes between one to two minutes.

Update 1: I do have antivirus software installed. I have disabled it but it has not solved the issue.

Update 2: I can confirm this is a problem specific to my desktop machine. I am yet to reproduce the problem on my laptop.

Makeweight answered 11/1, 2013 at 21:42 Comment(7)
This may be a stupid question, but is the program still running?Cankerous
This is almost always caused by anti-malware, it invariably gets very exited when it sees an EXE file appear from nowhere. Especially when it is Avast, a well-known troublemaker. Try disabling it first to see if the problem disappears.Byway
@Jimmy, no the program has stopped. I usually test something out, make changes, then go to debug again. I get this problem when it rebuilds after I made these changes.Makeweight
@Hans I have got antivirus installed, but I have not tried disabling it yet.Makeweight
Well, thanks for letting me know. Gack.Byway
Try rebooting maybe? You never know.Telecast
Sorry, maybe I should clarify. Rebooting would work, but the System process does release the file eventually - it doesn't stay locked. Normally, I would say it takes somewhere between one to two minutes for this to happen.Makeweight
M
9

I found a discussion on a forum with the title 'System process "anomaly"'.

This is taken from Jblom1986's post. His solution solved my problem. To make the changes go to the services tab using msconfig.exe.

"When the windows service named 'Application Experience' (a service which when something crashes finds a solution in the microsoft database) is turned off, another service named 'Search Indexer' (a service which is responsible for quickly finding files on a drive by indexing them) starts to malfunction. As a result, windows locks anything you have moved, copied or used for a few minutes to 'index' this file before releasing it after which you can delete that same file. It locks it with Process ID number 4 (PID:4)".

Edit: This was on a Windows 7 machine. I'm not sure if other versions of Windows have this error.

Makeweight answered 28/1, 2013 at 23:32 Comment(2)
It helped me. I've started the service 'AeLookupSvc' and the file locking effect has gone. Thanx a lot!Insomnia
In my case disabling of AeLookupSvc helped. When it was enabled it continuously caused build errors due to an attempt to modify the file which just has been created. serverfault.com/questions/1966/…Phi
I
0

Windows guarantees that a process will close all handles upon termination. Short of corrupt OS, your handles are closed when your process exits no matter what.

Most likely, you have an antivirus or similar process that is opening and scanning that file.

Ibeam answered 11/1, 2013 at 22:1 Comment(3)
I have antivirus installed. I have just tried disabling but I can still replicate the problem. If I wait long enough, I am able to rebuild successfully. I can sometimes speed this up by restarting Visual Studio and unplugging and plugging back in the Kinect device.Makeweight
Huh - sounds like some other process is grabbing that file temporarily. You can try disabling other things - such as anti-mal-ware, or the system indexing service. Or do you have something like Visual Assist installed? It rescans files. Something, at any rate, is opening a handle on that file. Patience should also work - whatever it is, if it is given time, presumably will finish and release that handle.Ibeam
Many years ago, it was indexing service that was causing my issue.Hortensiahorter

© 2022 - 2024 — McMap. All rights reserved.