Strange issue , we have created several exe sensors which work fine. 2 sensors that we have created lately use

System.Windows.Forms.WebBrowser object

within console exe. Console tests fine in command window, but when added as a sensor following event does not work private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

Is there some level of security that prevents some events from executing.

We are using 2012 window server , program is a simple console app using C# 4.0 framework the only difference is we are using web browser control .


Article Comments

Any specific user you're executing this with? Does this user have been logged in and started IE at least once (and configured it)?


Oct, 2016 - Permalink

You will need to capsulate the web browser control in its own class.
Code snippet in VB:

#Region " Classes "
    Private Class Browser
        Private Shared completed As Boolean = False
        Private Shared wb As WebBrowser

        Shared Function Main(ByVal url As String) As String
            completed = False
            wb = New WebBrowser()
            wb.ScriptErrorsSuppressed = True
            RemoveHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
            AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted

            wb.Navigate(New Uri(url))
            Dim maxWait As Integer = 150  '// wait for a maximum of 15 seconds

            While Not completed AndAlso maxWait > 0
                maxWait -= 1
                Application.DoEvents()
                Thread.Sleep(100)
            End While

            If maxWait = 0 Then Return ""
            Application.DoEvents()
            Return wb.DocumentText
        End Function

        Shared Sub wb_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
            Thread.Sleep(1000)
            completed = True
        End Sub
    End Class
#End Region

'// and call it like this
Dim content As String = Browser.Main("http://prtgtoolsfamily.com/")

Oct, 2016 - Permalink

Thanks! :)


Oct, 2016 - Permalink