问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/14287128/output-file-locked-by-another-process-when-building