在TCriticalSection上调用TryEnter方法时,结果始终为true.当然,如果能够获得锁定,这应该只返回true?
var MyCritSect: TCriticalSection; begin MyCritSect := TCriticalSection.Create; try // MyCritSect.Enter; Writeln(BoolToStr(MyCritSect.TryEnter, True)); // This should return True Writeln(BoolToStr(MyCritSect.TryEnter, True)); // This should return False? Readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
即使您取消注释该MyCritSect.Enter;
行,对于两次调用TryEnter,它仍会返回True.
我正在使用Delphi XE和Windows 10.