Problème avec la source: Empêcher une application de se lancer plus d'une fois
Bonjour je voulais utilisé la source ici pour empêcher mon application de se lancer plus d'une fois.
Donc je place le code dans le splashscreen de mon application
voic le code :
Code:
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Reflection
Imports System.Diagnostics
Public NotInheritable Class SplashScreen
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim file As String = Application.StartupPath + "\" + System.Reflection.Assembly.GetExecutingAssembly.GetName.Name + ".exe"
End Sub
'---------------------------------------------------
'--- construction d'un second Thread
'--- pour tester s'il y a bien une double excécution
'---------------------------------------------------
<STAThread()> _
Shared Sub Main()
If Not CheckProcess() Then
Application.Run(New SplashScreen)
Else
MessageBox.Show("Application déjà lancée", "Erreur")
Application.Exit()
End If
End Sub
'-----------------------------------------
'---
'--- Fonction : Test du processus
'---
'--- Entrée : Aucune
'--- Sortie : True ou false
'-----------------------------------------
Private Shared Function CheckProcess() As Boolean
Dim pcur As Process = Process.GetCurrentProcess
Dim ps As Process() = Process.GetProcesses
For Each p As Process In ps
If Not (pcur.Id = p.Id) Then
If pcur.ProcessName = p.ProcessName Then
Return True
End If
End If
Next
Return False
End Function
End Class |
Malheureusement j'arrive a lancer l'application plusieurs fois :(:(
Alors que la source fonctionne !!
Merci d'avance