Je suis un peu embété avec mon application.
Je voudrais l'arréter, puis la redemarrer, quand je suis sur qu'elle a été arrétée correctement. J'ai pensé qu'en synchronisant 2 Thread, ça pourrai répondre à mon besoin.
J'ai écris le code ci-dessous :
Mais problème. Est-ce que le myOldThreadEvent.Set(); va être réalisé après le Thread.CurrentThread.Abort();
Code : 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 class x { static AutoResetEvent myOldThreadEvent = new AutoResetEvent(false); static void Main() { Thread myNewThread = new Thread(new ThreadStart(MyNewThreadProc)); myReaderThread.Priority = ThreadPriority.AboveNormal; myReaderThread.Name = "NewThread"; myReaderThread.Start(); Thread.CurrentThread.Abort(); // Application.Exit(); myOldThreadEvent.Set(); } static void MyNewThreadProc() { Process myProcess = new Process(); myProcess.StartInfo.FileName = Application.ExecutablePath; // attend un evt du "Old" Thread myOldThreadEvent.WaitOne(); myProcess.Start(); } }:
:
:
Si je remplace par un Application.Exit(); je kill l'autre Thread, non ?
Bref, tout ça n'a pas l'air de fonctionner !
Partager