does anyone have a notion how not to use a Thread.Sleep? I know that the question is silly but, I have more than 3 days trying how not to use it, to be able to control a for.
I explain a little what I'm trying to do, I have a project which goes through "N" number of points given by the user along with an interval also given by the user, what the interval does is put a waiting time between point to point.
The point is that if I use Thread.Sleep when activating another timer next to the one that does the above, it also stays with that timeout (which it shouldn't be).
Base code annex (test project).
Timer 1: Timer 1 (list of coordinates/points given by the user)
List<Point> points = new List<Point>();
List<int> times = new List<int>();
foreach (ListViewItem item in PositionsListView.Items)
{
int x = Convert.ToInt32(item.Text);
int y = Convert.ToInt32(item.SubItems[1].Text);
times.Add(Convert.ToInt32(item.SubItems[2].Text));
points.Add(new Point(x, y));
}
try
{
for (int j = 0; j <= points.Count - 1; j++)
{
string value = Convert.ToString(points[j].Y * 65536 + points[j].X);
SendMessageA(Convert.ToInt32(this.Handle1), 513L, Convert.ToInt64(value), 8L);
SendMessageA(Convert.ToInt32(this.Handle1), 514L, Convert.ToInt64(value), 8L);
Thread.Sleep(times[j]); // Time interval between each point
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Timer 2: The one that controls everything (and triggers timer 3 that executes a click event)
if (GetAsyncKeyState(Keys.F1) != 0)
{
timer3.Start();
timer1.Start();
}
if (GetAsyncKeyState(Keys.F2) != 0)
{
timer1.Stop();
timer3.Stop();
}
if (GetAsyncKeyState(Keys.F3) != 0)
{
CapturarVentanaDeClick();
}
timer3.Interval = Convert.ToInt32(numericUpDown1.Value);
timer1.Interval = Interval;
Could someone guide me? I'm really kind of lost.
First of all, Thanks.