Anonymous user
Determine if only one instance is running: Difference between revisions
Determine if only one instance is running (view source)
Revision as of 04:15, 27 June 2011
, 12 years agoAdded Delphi example
(Added Delphi example) |
|||
Line 216:
(try (new ServerSocket *port* 10 (. InetAddress getLocalHost))
(catch IOException e (System/exit 0))) ; port taken, so app is already running </lang>
=={{header|Delphi}}==
<lang Delphi>program OneInstance;
{$APPTYPE CONSOLE}
uses SysUtils, Windows;
var
FMutex: THandle;
begin
FMutex := CreateMutex(nil, True, 'OneInstanceMutex');
if FMutex = 0 then
RaiseLastOSError
else
begin
try
if GetLastError = ERROR_ALREADY_EXISTS then
Writeln('Program already running. Closing...')
else
begin
// do stuff ...
Readln;
end;
finally
CloseHandle(FMutex);
end;
end;
end.</lang>
=={{header|Go}}==
Solution using O_CREATE|O_EXCL, and with messages and a 10 second sleep to let you test it.
|