The following sample demonstrates how to check on an already active instance:
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
Option Explicit
' a tcp/ip server socket is used as
' limited resource to check on a running
' application instance
Private sso As java#net#ServerSocket
' change to suitable port number as desired
Const appSpecificPort = 12589
Public Function isAppAlreadyStarted() As Boolean
On Error Goto ErrHandler
sso = New ServerSocket(appSpecificPort, 1)
' no error! We are the first
isAppAlreadyStarted = False
Exit Function
ErrHandler:
' socket already in use! There is somebody active already
isAppAlreadyStarted = True
End Function
Public Sub Form_Load()
If isAppAlreadyStarted() Then
MsgBox "App is already running!"
Else
MsgBox "App not running yet!"
End If
End Sub
|
To activate and show the previous instance, you'd have to play some more involved tricks.
One thread of the instance could listen on the server socket and execute a "show" method
once an appropriate client connect is coming along.
There might be some clever Java frameworks available to do it easier.
Happy experimenting!
A1880