我编写了一个 Service Application 程序。
我只想让程序运行一个实例,我在程序启动工程目录中,
写了如下代码
hMutex := CreateMutex(nil, True, APP_SIMPLE_NAME);
ret := GetLastError;
if ret = ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(hMutex);
MessageBox(Application.Handle, '系统提示,程序已经运行!', 'Servicedemo' ,
MB_OK + MB_DEFBUTTON1 + MB_ICONEXCLAMATION);
Exit;
end;
if StartService('Servicedemo') then
begin
Servicedemo.CreateForm(TDataMD,DataMD);
Servicedemo.CreateForm(TFrm_Main, Frm_Main);
Exit;
end;
Application.Initialize;
Application.CreateForm(TDataMD,DataMD);
Application.CreateForm(TFrm_Main, Frm_Main);
Application.Run;
if hMutex <> 0 then
begin
ReleaseMutex(hMutex);
CloseHandle(hMutex);
end;
但是当程序首先用服务在后台启动之后,再手动双击执行Servicedemo程序时,没有排斥到,还能启动N次
如果先双击运行Servicedemo程序,再在后台启动Servicedemo服务,是可以排斥到得。 这是什么原因,请大侠明鉴。。
我只想让程序运行一个实例,我在程序启动工程目录中,
写了如下代码
hMutex := CreateMutex(nil, True, APP_SIMPLE_NAME);
ret := GetLastError;
if ret = ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(hMutex);
MessageBox(Application.Handle, '系统提示,程序已经运行!', 'Servicedemo' ,
MB_OK + MB_DEFBUTTON1 + MB_ICONEXCLAMATION);
Exit;
end;
if StartService('Servicedemo') then
begin
Servicedemo.CreateForm(TDataMD,DataMD);
Servicedemo.CreateForm(TFrm_Main, Frm_Main);
Exit;
end;
Application.Initialize;
Application.CreateForm(TDataMD,DataMD);
Application.CreateForm(TFrm_Main, Frm_Main);
Application.Run;
if hMutex <> 0 then
begin
ReleaseMutex(hMutex);
CloseHandle(hMutex);
end;
但是当程序首先用服务在后台启动之后,再手动双击执行Servicedemo程序时,没有排斥到,还能启动N次
如果先双击运行Servicedemo程序,再在后台启动Servicedemo服务,是可以排斥到得。 这是什么原因,请大侠明鉴。。
解决方案 »
- doublebuffered的问题
- 谁能告诉我怎样把系统时间的值赋给一个记录的字段(在线等)
- 请问:Delphi+SQL2000字段显示问题?
- 如何用程序实现数据库的备份?
- 關于 windows.pas
- 用dbExpress连接MS SQL Server 2000的问题。
- 怎么用断点调试时看不出调试结果?方法是我没有用来,请你指点好吗?
- ComboBox问题!
- 如何实现按DBgrid或DBgridEH的行号或行数打印?
- 如何知道一个窗体已经建立了
- 关于delphi处理字符的一个问题?
- delphi img控件中装了一副图片,再把图片img.picture赋值给img2.picture.再form.print出来时图片有锯齿并且不清晰.
还是
当程序首先用服务在后台启动之后,再手动双击执行Servicedemo程序时,没有排斥到,还能启动N次