Hack Forums
[.NET] How to tell my program to wait until it has completed a task before it do a next task - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] How to tell my program to wait until it has completed a task before it do a next task (/showthread.php?tid=4589368)



How to tell my program to wait until it has completed a task before it do a next task - programtesting28 - Dec 17, 2014

I have a program that is works fine one minute but as soon as my internet connection slows it stops working.

This is because I have everything set by timers.

I have tried slowing the intervals and still it messes up from time to time.

There must be a way for the program to wait until it has completed one task and then automatically carry out the next task instead of hooking the next task up to a timer.

Here is an example of what I mean:
Code
WebBrowser1.navigate("http://www.google.com")
    [IF COMPLETED THEN MOVE ON TO NEXT TASK]
    WebBrowser1.Document.GetElementById("gbqfba").InvokeMember("click")

I'm pulling my hair out trying to work it figure it out lol

Thanks before 🤝😏


* - loopy90 - Dec 17, 2014

Here ya go.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx

so you could do
Code
Private Property pageready As Boolean = False

Private Sub Load()
    WebBrowser1.navigate("http://www.google.com")
    WaitForPageLoad()
    WebBrowser1.Document.GetElementById("gbqfba").InvokeMember("click")
End Sub

#Region "Page Loading Functions"
    Private Sub WaitForPageLoad()
      AddHandler Webbrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
      While Not pageready
      Application.DoEvents()
      End While
      pageready = False
    End Sub

    Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
      If Webbrowser1.ReadyState = WebBrowserReadyState.Complete Then
      pageready = True
      RemoveHandler Webbrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
      End If
    End Sub

#End Region



* - programtesting28 - Dec 17, 2014

ok thanks...
how about to automatically do next event after process finished vb.net ?
like after sending email then when the sending is finished, my application closed

thx before again


* - loopy90 - Dec 17, 2014

You could use the same thing probably.... Not sure though.