When calling the TryEnter method on TCriticalSection, the result is always right. Of course, this should only be returned if it is capable of capturing the castle?
var
MyCritSect: TCriticalSection;
begin
MyCritSect := TCriticalSection.Create;
try
Writeln(BoolToStr(MyCritSect.TryEnter, True));
Writeln(BoolToStr(MyCritSect.TryEnter, True));
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Even if you uncomment the line MyCritSect.Enter;, it still returns True for both TryEnter calls.
I am using Delphi XE and Windows 10.
source
share