Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
single instance run
#1
I need the generated exe to run as a single instance.

The following two functions are not working:
The functionality that exeThread_Test1 needs to implement: when the exe is run again, execute the subfunction (sub.osdTip).
The functionality that exeThread_Test2 needs to implement: when the exe is run again, restart the exe (first perform a soft close, then start it again).

Thanks in advance for any suggestions and help.

Function exeThread_Test1
 
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1)
,sub.osdTip
,ret

sub.osdTip

AddTrayIcon "cut.ico" "test_TcpSocket_server[]Ctrl+click to end."
#compile "__TcpSocket"
TcpSocket x.ServerStart(5032 &sub.OnClientConnected)

#sub OnClientConnected
function TcpSocket&client $clientIp param !*reserved

client.Receive(_s 1000)
out F"SERVER: client request: {_s}"
client.Send("response 1")

#sub osdTip
OsdHide "o1" 
OnScreenDisplay "TcpSocket_server is Running!" 0 0 0 "" 36 0x33331F 4|8|128 "o1" 0xFFFFFF

Function exeThread_Test2
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1)
,;shutdown -2 ;;not work
,shutdown -7
,run ExeFullPath
,ret

sub.osdTip

AddTrayIcon "cut.ico" "test_TcpSocket_server[]Ctrl+click to end."
#compile "__TcpSocket"
TcpSocket x.ServerStart(5032 &sub.OnClientConnected)

#sub OnClientConnected
function TcpSocket&client $clientIp param !*reserved

client.Receive(_s 1000)
out F"SERVER: client request: {_s}"
client.Send("response 1")

#sub osdTip
OsdHide "o1" 
OnScreenDisplay "TcpSocket_server is Running!" 0 0 0 "" 36 0x33331F 4|8|128 "o1" 0xFFFFFF
#2
It is in the help file.
#3
Thanks for your reminder. I found a similar feature in the link below.
https://www.quickmacros.com/help/User/ID...eadRunning

I’m a bit confused: is threadName the name of the exe? If the same exe uses a different name, is it still considered the same running instance?
Also, how can the exe restart itself automatically? I didn’t find the answer in the help documentation.
#4
No, look for mutex in the exe help page.
#5
The following code still does not work. How can I determine the value of mutex_my_exe? Sometimes, the same exe file has different file names, but it is still the same exe instance. How can I solve this problem?

Macro Macro8
Code:
Copy      Help
;at the beginning of exe main function:
SetLastError 0
__Handle m=CreateMutex(0 1 "Macro8") ::
if(!m) mes- "Error"
if(GetLastError=ERROR_ALREADY_EXISTS) ;;another instance of your exe is running
,;possibly execute some code here
,sub.osdTip
,ret ;;exit exe

sub.osdTip

AddTrayIcon "cut.ico" "test_TcpSocket_server[]Ctrl+click to end."
#compile "__TcpSocket"
TcpSocket x.ServerStart(5032 &sub.OnClientConnected)

#sub OnClientConnected
function TcpSocket&client $clientIp param !*reserved

client.Receive(_s 1000)
out F"SERVER: client request: {_s}"
client.Send("response 1")

#sub osdTip
OsdHide "o1"
OnScreenDisplay "TcpSocket_server is Running!" 0 0 0 "" 36 0x33331F 4|8|128 "o1" 0xFFFFFF
#6
What value? Mutexes don't have a value. The mutex name is used to detect other processes of your app or another app that uses that mutex name.
#7
Sorry, I don't know much about programming in this area.
The following code still doesn't work. After running the exe, executing it again does not display the OSD text

Macro Macro8
Code:
Copy      Help
;at the beginning of exe main function:
SetLastError 0
__Handle m=CreateMutex(0 1 "mutex_my_exe")
if(!m) mes- "Error"
if(GetLastError=ERROR_ALREADY_EXISTS) ;;another instance of your exe is running
,;possibly execute some code here
,sub.osdTip
,ret ;;exit exe

sub.osdTip

AddTrayIcon "cut.ico" "test_TcpSocket_server[]Ctrl+click to end."
#compile "__TcpSocket"
TcpSocket x.ServerStart(5032 &sub.OnClientConnected)

#sub OnClientConnected
function TcpSocket&client $clientIp param !*reserved

client.Receive(_s 1000)
out F"SERVER: client request: {_s}"
client.Send("response 1")

#sub osdTip
OsdHide "o1"
OnScreenDisplay "TcpSocket_server is Running!" 10 0 0 "" 36 0x33331F 4|8 "o1" 0xFFFFFF
#8
Probably it's the OnScreenDisplay problem in exe. Need to wait until OSD closed. I don't remember how.
#9
I can't answer the question about restarting. Either QM does not have an "easier than all others do it" way or I forgot it.
#10
Quote:Probably it's the OnScreenDisplay problem in exe. Need to wait until OSD closed

Using the mes function still doesn't work  Huh
 
Code:
Copy      Help
if(GetLastError=ERROR_ALREADY_EXISTS) ;;another instance of your exe is running
,;possibly execute some code here
,;sub.osdTip ;;no work
,mes "running!" ;;no work
,ret ;;exit exe

I just want to make it so that when the EXE program is run again, a message pops up to inform the user that the program is already running.
For applications with a system tray icon, this feature is very useful.

If implementing this in QM is too complicated, please skip it. Maybe, at some point in the future, I'll find a solution.
#11
I don't remember, maybe is applied Properties > Macro > If running.
#12
Quote:maybe is applied Properties > Macro > If running.
Executing the code in a macro doesn't work — it must be a function. I tested it in a macro without success, but it worked after converting it into a function.


Thanks for your help.

The issue has been resolved — the flags parameter in OnScreenDisplay needs to include the flag 2 to make the function execute synchronously.


Forum Jump:


Users browsing this thread: 1 Guest(s)