I have been struggling with this problem for a while and would appreciated any help.
I am trying to use a third party class library in my console application to obtain PageRank for a specific url on a timely bases (every 24 hours). If I call my "getPageRank" method using a while loop and a thread.sleep() everything works fine. However, when I try to use the System.timers.Timer object, my program does not execute the functions from the 3rd party DLL (in my case, pr.GetPageRank(path) does not get executed), and so the application does not progress beyond that point. I eventually end up getting the following error:
The CLR has been unable to transition from COM context 0x1a0c38 to COM context 0x1a0da8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
My code is as follow:
Private pr As New htmlsnap2Net.CHtmlSnap
Private WithEvents MainTimer As New System.Timers.Timer
MainTimer.Interval = 86400000
MainTimer.Enabled = True
MainTimer.AutoReset = True
Console.WriteLine("Press any key to end!")
Private Sub MainTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MainTimer.Elapsed
Console.WriteLine("PageRank: " & ObtainPageRank("my url goes here"))
Private Function ObtainPageRank(ByVal path As String) As Integer
Dim pagerank As Integer = 0
pagerank = pr.GetPageRank(path)