Excuse my English; I have a problem with threads: I have a WinForm, in it I have two buttons (Play & Pause) I wish that when you press the PLAY button, if it is created the thread, thought and start, and the PAUSE button to pause the thread. Then if the thread is paused, pressing the PLAY button resumes the thread from where it left off. Like a video game .... In Java I succeed doing something,
Runnable h = new MiHilo();
Thread t = new Thread(h);
public void PLAYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PLAYActionPerformed
if (t.isAlive())
{
t.resume();
}
else
{
h = new MiHilo();
t = new Thread(h);
t.start();
}
}
private void PAUSEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PAUSEActionPerformed
if (!t.isAlive())
{
JOptionPane.showMessageDialog(null, " ¿En qué está pensando?\nEs imposible pausar algo que no ha empezado.",
"David", JOptionPane.ERROR_MESSAGE);
}
else
{
t.suspend();
}
}
class MiHilo implements Runnable
{
public void run()
{
// Code here...
}
}
How I can do this in C #? What if I would like, if not too much trouble to tell me an example of how to do something basic, Pausing and resuming, something simple, like a single WinForm with a label, and two buttons (Play & Pause) when starting the label is written 0, if hit Play, it starts a thread that calls a function that has a for which varies from 1-1000 with a Sleep of 1 second to display as text on the label, and pause, when pressed would pause this count progressive, then the play would give, but without using Timers ...
Hope it's not too much to ask, with that example I could adapt it to what I want.
Thank you for your time!