If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
A one instance
21 posts
• Page 1 of 3 • 1, 2, 3
A one instance
How to allow to run only one instance of a program?
Thanks.
Thanks.
- Shoo
- Posts: 33
- Joined: Fri Sep 02, 2011 8:37 am
- Location: Russia
Re: A one instance
One way would be to use the Ruby Module, and write some Ruby code to see if there is already an instance running.
Looking at some web posts it seems people open a file and lock it, if the file is already open then don't allow the 2nd instance (ie. close it straight away).
Here some Ruby Code I found that could be tweaked to do this I think:
Looking at some web posts it seems people open a file and lock it, if the file is already open then don't allow the 2nd instance (ie. close it straight away).
Here some Ruby Code I found that could be tweaked to do this I think:
- Code: Select all
def log(msg)
output 0, "#{$$} #{msg}"
end
def lock
File.open("test.loc", File::RDWR|File::CREAT, 0644) {|f|
log "Attempting to lock..."
if (f.flock(File::LOCK_EX | File::LOCK_NB) == false)
log "Another instance is already running! Exiting"
abort
end
log "Lock acquired"
f.rewind
f.write($$)
f.flush
10.times do |i|
log "Doing work... #{i}"
sleep(1)
end
log "Exiting"
sleep(1)
}
end
def event i,v,t
lock
end
- Embedded
- Posts: 143
- Joined: Sat Oct 30, 2010 1:42 pm
Re: A one instance
Oh!.. I have a FlowStone 1.1.2((((
Can in it establish some flag to see that one instance is already running?
Can in it establish some flag to see that one instance is already running?
- Shoo
- Posts: 33
- Joined: Fri Sep 02, 2011 8:37 am
- Location: Russia
Re: A one instance
You could write a text file to disk, if it exists then close the second instance. But you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).
Also if for some reason your app. crashes and doesn't close formally the text file will still be there and then block you starting instance one!
So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.
My advice is to Get FlowStone V2 and do it properly using Ruby!
Also if for some reason your app. crashes and doesn't close formally the text file will still be there and then block you starting instance one!
So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.
My advice is to Get FlowStone V2 and do it properly using Ruby!
- Embedded
- Posts: 143
- Joined: Sat Oct 30, 2010 1:42 pm
Re: A one instance
Embedded wrote:My advice is to Get FlowStone V2
This decide my boss...
Embedded wrote:So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.
It's a great idea!
Thank you very much!
- Shoo
- Posts: 33
- Joined: Fri Sep 02, 2011 8:37 am
- Location: Russia
Re: A one instance
Embedded wrote:you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).
How hide (or disable) this elements (and the <Alt-F4>) ?
- Attachments
-
- quits.jpg (21.29 KiB) Viewed 26253 times
- Shoo
- Posts: 33
- Joined: Fri Sep 02, 2011 8:37 am
- Location: Russia
Re: A one instance
The only way is to use the fullscreen mode.
Hence why it's better to do this the Ruby way.
Hence why it's better to do this the Ruby way.
- Embedded
- Posts: 143
- Joined: Sat Oct 30, 2010 1:42 pm
Re: A one instance
Is it possible to use as the flag a presence of signal on some port or device busy?
- Shoo
- Posts: 33
- Joined: Fri Sep 02, 2011 8:37 am
- Location: Russia
Re: A one instance
Another idea would be to setup inter application communication using UDP and the network modules.
So if you set up a network Server on a port (say 80) in your FlowStone application to listen for a second instance, when a second instance was started (Client) it would send out a message get a response then shut down.
So if you set up a network Server on a port (say 80) in your FlowStone application to listen for a second instance, when a second instance was started (Client) it would send out a message get a response then shut down.
- DSP
- Posts: 150
- Joined: Fri May 14, 2010 10:55 pm
Re: A one instance
Embedded wrote:You could write a text file to disk, if it exists then close the second instance. But you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).
Also if for some reason your app. crashes and doesn't close formally the text file will still be there and then block you starting instance one!
So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.
The TaskList command can make a list of instances of a given program. Then compare if the lines of text exceeds more than that of one program then kill the process. I can build example if needed.
- Morph
- Posts: 53
- Joined: Tue Jul 13, 2010 1:59 pm
21 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 59 guests