|
-
June 3rd, 2008, 12:10 PM
#1
openning files with vb.net apps 2
i have made a video player program and i've set it up so when a user double clicks on a video file the program opens and the video plays. however if the program is running and the user double clicks on a video file it opens a new window and plays the video at the same time. can anyone tell me how to set it so if the program is running and the user tries to open it again it brings the currently running version of the program to the front and passes a file name (if the user has openned a video file for example)?
-
June 4th, 2008, 01:14 AM
#2
Re: openning files with vb.net apps 2
You can perhaps do it like that, but I'd recoomend making your program a Single Instance application, meaning, only one instance of your program can run. Because you are dealing with possible large video files, it would be best.
You haven't stated which version of VB you are using ( as politely asked here : http://www.codeguru.com/forum/showthread.php?t=403073 )
If you're using VB 2005, you can set up this, by going to the project's properties, but I remember a guy here on the forum ( last year ), he had problems with his firewall when he set this setting ( here is the thread : http://www.codeguru.com/forum/showth...ghlight=comodo )
IMHO, the best way would be to do something like this :
Code:
Public Sub main()
'You can use a Mutex object to synchronize between threads and across processes.
' Although Mutex doesn't have all the wait and pulse functionality of the Monitor class, it does offer the creation of named mutexes that can be used between processes.
'You call WaitOne, WaitAll, or WaitAny to request ownership of the Mutex.
'The state of the Mutex is signaled if no thread owns it.
'If a thread owns a Mutex, that thread can specify the same Mutex in repeated wait-request calls
'without blocking its execution; however, it must release the Mutex as many times to release ownership.
'If a thread terminates normally while owning a Mutex,
'the state of the Mutex is set to signaled and the next waiting thread gets ownership.
Dim AppMutex As System.Threading.Mutex = New System.Threading.Mutex(False, "ThisShouldONLYRunOnce")
Dim AppRunning As Boolean = Not AppMutex.WaitOne(0, False)
If AppRunning Then
MessageBox.Show("Apprentice Is Already Running!", "Apprentice", MessageBoxButtons.OK, MessageBoxIcon.Error)
Application.Exit()
Dim AppHandle As String
AppHandle = FindWindow(Nothing, "Student Information") 'Get Title of already running Apprentice form
AppHandle = SetForegroundWindow(AppHandle) '"Focus" the window ( restore & bring to front )
Else
Application.Run(New frmAppPersInfo) 'if first fire
End If
End Sub
You can of course just substitue my program name(s) with yours. There are other ways, but this way works on Windows Vista as well, where the others don't
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|