You are not logged in.

giucleand

Beginner

  • "giucleand" is male
  • "giucleand" started this thread

Posts: 11

Date of registration: Oct 27th 2009

Location: Romania

Occupation: sysadmin

  • Send private message

1

Tuesday, October 19th 2010, 8:48am

Previous instance

Could anyone tell me how it's possible to detect the previous instance of the application (App.PrevInstance of VB6) and, furthermore, activate it, by making it visible on the screen, even if it was previously minimized in taskbar or, even better for me, switching it from invisible status to visible?
I couldn't find how to do that browsing the forum, so I'll just ask.
Thank you so much

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Tuesday, October 19th 2010, 9:05pm

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

giucleand

Beginner

  • "giucleand" is male
  • "giucleand" started this thread

Posts: 11

Date of registration: Oct 27th 2009

Location: Romania

Occupation: sysadmin

  • Send private message

3

Wednesday, October 20th 2010, 10:04am

Smart approach, thank you.

Rate this thread
WoltLab Burning Board