I have a form that contains the attached code that starts a new thread.
Thewre are three routines. StartMomnitoring starts the thread DoMonitor, and
StopMonitor stops the thread. The "SendRec" routine sends amessage out a
Tcp/Ip socket and returns the returned value. As the DoMonitor thread shows,
there is a sleep of 1 msec so I would expect a rate depending on the
internet latency. Here is the problem..
When started, I get an exchange rate of about 2 per second. However, if I
right click on the title barof the form, I get a pop up window with move,
close, etc options, and the rate increases to about 30 per second. I have
thought about trhread priority but changing the priority makes no difference.
Any thoughts anybody??
Public Sub StartMonitoring()
Dim t1 As New Thread(AddressOf DoMonitor)
Console.WriteLine("starting thread")
't1.Priority = ThreadPriority.Highest
t1.Start()
End Sub
Public Sub StopMonitoring()
Console.WriteLine("stopping thread")
RunStop = 0
End Sub
Sub DoMonitor()
Dim s As String
Dim ss As String
Dim p() As String
Dim pp As String
Dim I As Int32 = 0
Dim xx As Integer
RunStop = 1
Dim OFile As New StreamWriter(Application.StartupPath &
"\Data\LogFile.txt")
Do
If I = Count Then I = 0
s = Ant0.WriteRead(Cmd(I))
ss = Now.ToString("hh:mm:ss") & "," & s
Console.WriteLine(ss)
OFile.WriteLine(ss)
MonBox.Text = ss
'Thread.Sleep(10)
If RunStop = 0 Then Exit Do
I += 1
Loop
OFile.Close()
End Sub