Bonjour le forum,

je suis débutant en PowerShell (désoler pour les erreur de langage). je chercher à déclencher une fonction boucle par un bouton (jusqu'ici ça se passe bien) et la stopper par un autre.
voici mon code simplifié(c'est pour le principe) en réalité ma fonction "MaBoucle" est beaucoup plus complexe.
Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function MaBoucle(){
	while ($run -eq $true) { 
		$Date2Départ =  [DateTime]::NOW
	}
}
 
 
#################################################
# CONFIGURATION DE LA WINDOWS FORM
#################################################
#Forme 
	# Chargement des assemblies
	[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
	[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
	# Creation de la form principale
	$form = New-Object Windows.Forms.Form
	# Pour bloquer le resize du form et supprimer les icones Minimize and Maximize
	$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
	$form.MaximizeBox = $False
	$form.MinimizeBox = $False
	# Choix du titre
	$form.Text = "Job JCI - Mailling"
	# Choix de la taille
	$form.Size = New-Object System.Drawing.Size(400,250)
 
#################################################
# AJOUT DES COMPOSANTS
#################################################
#Le point (0;0) correspond au coin supérieur gauche de la fenêtre.
#button_GO
	$button_GO = New-Object System.Windows.Forms.Button
	$button_GO.Text = "GO"
	$button_GO.Size = New-Object System.Drawing.Size(355,40)
	$button_GO.Location = New-Object System.Drawing.Size(20,50)
	# Insertion du bouton Quitter dans la Windows Form principale
 
#button_STOP
	$button_STOP = New-Object System.Windows.Forms.Button
	$button_STOP.Text = "STOP"
	$button_STOP.Size = New-Object System.Drawing.Size(355,40)
	$button_STOP.Location = New-Object System.Drawing.Size(20,100)
	# Insertion du bouton Quitter dans la Windows Form principale
 
 
#################################################
# GESTION DES EVENEMENTS
#################################################
 
# Gestion event quand on clique sur le bouton OK
$button_GO.Add_Click(
{
	$run = $true
	# appelle de ma fonction 
	MaBoucle
})	
# Gestion event quand on clique sur le bouton Fermer
$button_STOP.Add_Click(
{	
	$run = $false
	$Message= [System.Windows.Forms.MessageBox]::Show($Date2Départ, "Information", 0, "Information")
	$form.Close()
})
 
 
#################################################
# INSERTION DES COMPOSANTS
#################################################
	$form.Controls.Add($button_GO)
	$form.Controls.Add($button_STOP)
	# Affichage de la Windows
	$form.ShowDialog()
#################################################
# FIN CONFIGURATION DE LA WINDOWS FORM
#################################################

je pense que je m'y prend mal, le programme se déroule en série alors que je cherche à avoir ma forme et ma fonction en exécution parallèle mais dépendante.
Pouvez vous m’aiguiller ?
je suis avec PowerGui script Editor V3.8.0.129