Singleton; Mutex

Hello!

Had some updates to my windows 10 system yesterday and now see, that Mutex does not work anymore for permitting application only be started once.

[code]// *** force singleton app
mMutex = New Mutex(“MutexSingle”)

If Not mMutex.TryEnter Then
MsgBox(“start only once…”)
mMutex = Nil
Quit
End If

mMutex = Nil[/code]

Any alternative for Mutex to force app as singleton?
Anybody else with this problem?
Wrong code?
Anything from Monkeybread Software?

Thanks a lot in advance!

Did you try MutexMBS class?

how come you are setting mMutex to nil? this will allow a second application to launch as the Mutex is getting destroyed after the if check.

Thanks

[quote=441992:@Hans-Norbert Gratzal]Hello!

Had some updates to my windows 10 system yesterday and now see, that Mutex does not work anymore for permitting application only be started once.

[code]// *** force singleton app
mMutex = New Mutex(“MutexSingle”)

If Not mMutex.TryEnter Then
MsgBox(“start only once…”)
mMutex = Nil
Quit
End If

mMutex = Nil[/code]

Any alternative for Mutex to force app as singleton?
Anybody else with this problem?
Wrong code?
Anything from Monkeybread Software?

Thanks a lot in advance![/quote]

Keep the mutex alive.

[code]// *** force singleton app
mMutex = New Mutex(App.ExecutableFile.Name)

If Not mMutex.TryEnter Then
MsgBox(“start only once…”)
mMutex = Nil
Quit
End If

// continue from here

[/code]

In my Windows desktop projects this works fine .

As Connor mentions above, don’t put

mMutex = Nil

at the end of your code above, that is almost instantly getting rid of the mutex.

See the code sample here http://documentation.xojo.com/api/language/mutex.html

[quote=442006:@JulianS]As Connor mentions above, don’t put

mMutex = Nil
at the end of your code above, that is almost instantly getting rid of the mutex.[/quote]
@JulianS - of course - thanks for correcting me.

Thanks a lot!!!

mMutex = Nil

sounds obvious… damn…

Funny it worked before. But garbage collection could have kept it somehow.

Ok, my fault!

Thanks again for helping!!!