Есть класс для инвертирования движения мыши. При вызове метода Stop программа продолжает работать. При применении Abort прога закрывается. Как остановить цикл в методе MouseLoop?
class Inverter
{
private Point currentPosition;
private bool exit;
public void Start()
{
currentPosition = Cursor.Position;
exit = false;
(new Thread(new ThreadStart(MouseLoop))).Start();
}
public void Stop()
{exit = true;}
private void MouseLoop()
{
Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (!exit)
{
Point newPosition = Cursor.Position;
int right = currentPosition.X - (newPosition.X - currentPosition.X);
int maxWidth = SystemInformation.VirtualScreen.Width;
if (right >= maxWidth)
{
right -= 3;
}
else if (right <= 0)
{
right += 1;
}
int bottom = currentPosition.Y - (newPosition.Y - currentPosition.Y);
int maxHeight = SystemInformation.VirtualScreen.Height;
if (bottom >= maxHeight)
{
bottom -= 3;
}
else if (bottom <= 0)
{
bottom += 1;
}
Cursor.Position = new Point(right, bottom);
currentPosition = Cursor.Position;
Thread.Sleep(1);
}}}}
abort
если у вашего потока нет переменной? Можете код показать с методомabort
?Abort
?