Yes, this is not correct code. It will fail when a second thread also enters the lock and it is already held. The locked variable must be a local variable to ensure that it has thread affinity. Fix:
public override void LockIt()
{
bool locked = false;
try
{
spinLock.Enter(ref locked);
}
finally
{
if(locked)
spinLock.Exit();
}
}
Do note that the code otherwise makes no sense, there is no point in entering a lock and then immediately exit it again. I assume that's your real homework assignment.