I want to make a small Wheel of Fortune game, but I have issues making an event that rotates the image
This is the code I have now, but it only seems to run the _thread once
private readonly Timer _timer;
private Thread _thread;
private int _angle;
public MainWindow()
{
InitializeComponent();
_timer = new Timer(500);
_timer.Elapsed += RotateWheelEvent;
_timer.Start();
_angle = 0;
SetupRotationThread();
_thread.Start();
}
public void RotateWheelEvent(object sender, EventArgs args)
{
_thread.Abort();
_angle = _angle + 15;
_thread.Start();
}
public void SetupRotationThread()
{
var rotatetransform = new RotateTransform(_angle);
_thread = new Thread(
delegate()
{
ImageWheel.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.SystemIdle,
TimeSpan.FromSeconds(1),
new Action(
delegate()
{
ImageWheel.RenderTransformOrigin = new Point(0.5, 0.5);
ImageWheel.RenderTransform = rotatetransform;
}
));
});
}
Start
the thread that you calledAbort
on.Abort
'ing threads is generally a bad practice too.