Hallo,
also ich finde gleich mehrere Quellen die Aussagen warum diese Funktionen veraltet sind.
Zum Beispiel:
msdn.microsoft.com/e....thread.suspend.aspx
Caution:
Do not use the Suspend and Resume methods to synchronize the activities of threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while it holds locks during a security permission evaluation, other threads in the AppDomain might be blocked. If you suspend a thread while it is executing a class constructor, other threads in the AppDomain that attempt to use that class are blocked. Deadlocks can occur very easily.
...
D.h. du könntest mit Thread.suspend einen Zustand generieren der deine ganze Anwendung lahm legt oder undefiniertes Verhalten hervorruft. Deshalb sollst du alternative Synchronisierungsmöglichkeiten verwenden. Dafür kannst du unter anderem Locks, Monitor oder Events verwenden. (
msdn.microsoft.com/e...ibrary/ms173179.aspx
Um zu entscheiden was in deinem Fall das Richtige ist, benötigt man mehr Informationen. Ich Vermute bei deinem Problem reicht eine Funktion wie worker.Pause, in dem einfach eine Klassenvariable auf false gesetzt wird, schon aus.
Gruß Daniel
Bsp:
C#-Quelltext
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:
| bool m_pause = false; public void Pause() { m_pause = true; }
public void Resume() { m_pause = false; }
public void Start() { Produce(); }
public void Produce() { while(true) { if (m_pause == false) { ProduceOutput(); } } } |