Run function(2) after function(1)

Posts 16 of 6 · Page 1 of 1
Run function(2) after function(1)
Hi there I'm currently having some issues with my code
I Want to run the function(1) then after that finished loading I want to load funtion(2) atm the function 2 loads faster then function 1 so everything gets messed up
Quote Originally Posted by ImAzey View Post
Hi there I'm currently having some issues with my code
I Want to run the function(1) then after that finished loading I want to load funtion(2) atm the function 2 loads faster then function 1 so everything gets messed up
So you are suffering race conditions?

Show the code, it's easier to see if there's something wrong.
Quote Originally Posted by R3DDOT View Post


So you are suffering race conditions?

Show the code, it's easier to see if there's something wrong.
Function 2
HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("in put");
foreach (HtmlElement el in elc)
{
if (el.GetAttribute("type").Equals("submit"))
{
el.InvokeMember("Click");
}
Function 1
HtmlElementCollection elements = browser.Document.All;
foreach (HtmlElement element in elements)
{
if (element.GetAttribute("className") == "spHipNoClear hipInputText primaryTextInput")
{
element.SetAttribute("value", captchaResponse);
Quote Originally Posted by ImAzey View Post
Function 1
That's not enough.

I can't see when they are called, and that's what matters.
You can add a delay in between:
Code:
System.Threading.Thread.Sleep(500) //Time in milliseconds
Write methods for them such as:

Code:
        private bool func1()
        {
            HtmlElementCollection elements = browser.Document.All;
            foreach (HtmlElement element in elements)
            {
                if (element.GetAttribute("className") == "spHipNoClear hipInputText primaryTextInput")
                {
                    element.SetAttribute("value", captchaResponse);
                }
            }
            return true;
        }
        private bool func2()
        {
            HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("in put");
            foreach (HtmlElement el in elc)
            {
                if (el.GetAttribute("type").Equals("submit"))
                {
                    el.InvokeMember("Click");
                }
            }
            return true;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //if func1 is executed, proceed to func2
            if (func1() == true)
            {
                func2();
            }
        }
you're welcome
Posts 16 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?