Guest User

Untitled

a guest
Oct 6th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.44 KB | None | 0 0
  1. Public Class Confictura
  2.  
  3.  
  4.     Dim Writer As New ThreadSafeWriter
  5.     Dim WithEvents DownloadTimer As New System.Timers.Timer
  6.  
  7.  
  8.  
  9.     Public Sub Main() Handles MyBase.Loaded
  10.  
  11.         ' Increase max concurrent connectinos above default
  12.         System.Net.ServicePointManager.DefaultConnectionLimit = 100
  13.  
  14.         DownloadTimer.Interval = 50
  15.         DownloadTimer.AutoReset = True
  16.         DownloadTimer.Start()
  17.  
  18.     End Sub
  19.  
  20.  
  21.  
  22.     Public Sub GetCounterValue() Handles DownloadTimer.Elapsed
  23.  
  24.         Try
  25.  
  26.             Dim Client As New WebClient
  27.             Dim Response As String = Client.DownloadString("http://www.conficturaindustries.com/c.php")
  28.  
  29.             Response = Response.Replace("<img src=""images/", "")
  30.             Response = Response.Replace(".gif", "")
  31.             Response = Response.Replace(""">", "")
  32.  
  33.             Writer.WriteLine(Now.Ticks & "," & Response)
  34.  
  35.         Catch ex As Exception
  36.         End Try
  37.  
  38.     End Sub
  39.  
  40.  
  41.  
  42. End Class
  43.  
  44.  
  45.  
  46.  
  47. Public Class ThreadSafeWriter
  48.  
  49.  
  50.     Dim File As New IO.FileStream("counter.csv", IO.FileMode.Append)
  51.     Dim Writer As New IO.StreamWriter(File)
  52.  
  53.  
  54.  
  55.     Public Sub WriteLine(Data As String)
  56.  
  57.         SyncLock Writer
  58.             Writer.WriteLine(Data)
  59.         End SyncLock
  60.  
  61.     End Sub
  62.  
  63.  
  64.  
  65.     Public Sub Close()
  66.  
  67.         Try
  68.  
  69.             Writer.Close()
  70.             File.Close()
  71.  
  72.         Catch ex As Exception
  73.  
  74.         End Try
  75.  
  76.     End Sub
  77.  
  78.  
  79.  
  80. End Class
Add Comment
Please, Sign In to add comment