在服务模块中加入以下代码
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);
begin
CreateMutex(nil, FALSE, 'Project1'); //uses Winapi.Windows
if GetLastError = ERROR_ALREADY_EXISTS then
begin
//Application.Terminate;
ExitProcess(0); //新版本有效
end;
end;
该段代码在服务模块初始化前创建了一个互斥体(Mutex),用于确保只有一个实例运行。如果互斥体已经存在(即错误代码ERROR_ALREADY_EXISTS),则通过ExitProcess终止进程,防止多个实例同时运行。
7609

被折叠的 条评论
为什么被折叠?



