Have a problem with pausing loop. Can't use thread.sleep and timer control.
Hello,
I am just a beginner programmer, maybe there are some
ways to do it, but I couldn't find an aswer in like 3 hours browsing
the internet. All I need is to pause the cycle (but not freeze any
controls), and then resume it. On a pause it is not supposed to do
anything, but it cannot freeze. My program is like that: it does the
double mouseclick on a label in a website, which value changes every 1
second, then start a never-ending loop and start getting another value,
from a different label. Sounds simple, but the problem is that my
program is getting stuck because of that never-ending loop and I need a
delay every loop.
Firstly, I cannot use thread.sleep because it
gets my webbrowser control frozen. And I cannot use
Application.DoEvents(), because i need to pause loops in different
places in the same method.
Secondly, I would use a timer, but I
can't, because the time, after I execute the code, is not constant and
may differ. I just need to do it before processing every loop.
I have also tryed multi-threading, but I'm not sure if I done
everything right, so if it would help, please write me some code about
it :)
I would appriciate any help. If you know any other methods that would help, please post it.
Here is my code:
public int VardX, VardY, SecX, SecY, SiulX, SiulY, SafeX, SafeY;
public int i = 1;
public IHTMLDocument2 htmlDocument;
public IHTMLSelectionObject currentSelection_sek, currentSelection_vard;
public IHTMLTxtRange range_sek, range_vard;
private void button1_Click(object sender, EventArgs e)
{
htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
while (i != 0)
{
{FIRST 1 SECOND DELAY HERE, AFTER WHICH EXECUTE THE FOLLOWING CODE}
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(SecX, SecY);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, SecX, SecY, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, SecX, SecY, 0, 0);
//Double click on the label I need.
currentSelection_sek = htmlDocument.selection;
range_sek = currentSelection_sek.createRange() as IHTMLTxtRange;
//Specify the selection
while ((range_sek.text!=null)&&(range_sek.text.Length > 8)&&(range_sek.text.Length < 22))
//Executes when I get something that i need selected.
{
{ANOTHER 10 MILISECONDS DELAY HERE, AFTER WHICH EXECUTE THE FOLLOWING CODE}
if (range_sek.text.Equals(listBox2.Text))
//Checks if the selection already has the value that i need. Must check it every loop.
{...Check another value and so on...}