16 December 2019, 09:41 | #1 |
Registered User
Join Date: Nov 2019
Location: Celle / Germany
Posts: 145
|
How to check if a Task is already running?
I want to check, if my program has been started before to prevent another instance by double clicking the icon again by mistake.
I cannot use FindTask() as it will always find itself, so I cannot find the other task that MAY be started before. |
16 December 2019, 09:58 | #2 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
AttemptSemaphore?
|
16 December 2019, 11:24 | #3 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
Check if program message port is open or not maybe?
|
16 December 2019, 11:47 | #4 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
I check with
jsr (_LVOFindPort,a6)if there is already a named port, possibly added with a precedent jsr (_LVOAddPort,a6). There are probably better methods but this works, in every kickstart, and is very simple. |
23 December 2019, 08:22 | #5 |
Registered User
|
Another possibility is to Lock() your program's executable with exclusive access mode straight after start.
This way you get a meaningful error message via IoErr() (202: object is busy), if it's opened again. However, there is a caveat, if your program crashes, the lock might remain open forever, so prepare special cleanup code for this. The FindPort solution is nice, too, but you should be careful about name collisions with other applications running. And beware of race conditions occuring by both methods! Always sempahore protect such code! |
28 February 2020, 10:30 | #6 | |
Registered User
Join Date: Feb 2020
Location: Munich/Germany
Posts: 2
|
Quote:
|
|
29 February 2020, 21:05 | #7 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Ia the port introduces race conditions, and has to be protected with a semaphore, then wouldn't it make more sense to use AttemptSemaphore already mentioned by deimos?
After all you will need a semaphore anyway, and this is a exactly the purpose this is for. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
pc task 4.4:) | 8bitbob | support.Apps | 42 | 25 August 2023 19:29 |
PC Task 4.4 | Jimbo | request.Apps | 61 | 25 February 2023 05:56 |
Once again PC Task! | lurkist | request.Apps | 58 | 04 July 2022 23:16 |
Simple way to check that the game is running on a CD32? | earok | Coders. Blitz Basic | 11 | 18 September 2017 15:19 |
PC-Task | DyLucke | request.Apps | 18 | 06 February 2010 21:52 |
|
|