I have an application where I am using a System Thread to capture the screen
& Broadcast it to clients. Its "working", but the timing on the background
thread gets wildly erratic at times. Some times, its right away, some times
after 10 seconds. I have included the setup of the process and the outline
of the Call Back Method.
As posted, the callback method can be mildly erratic (only doing a
debug.writeline) I am guessing up to an 80% variance on the time it takes to
print the Debug messages with an average variance of about 15%-25%. It gets
even worse when I add in the real program logic with up to 300% variance on
the loop timing.
If I stop & start the thread, it always clears up the timing for a few
seconds. Then its back to its crazy erratic self.
I think it makes since to try this on another box, but I need to know if my
approach is a good one or if I am doing something wildly silly to start
with.
Thanks!
Setting up the Process:
MyBroadcast = New BroadcastClass(Broad_IPAddress,
Convert.ToInt16(Broad_Port), PollingDelay, BroadcastInterleaveDelay)
MyBroadcast.Background_Capture_Process = New
System.Threading.Thread(AddressOf MyBroadcast.Capture_Process)
MyBroadcast.My_Process_Enabled = True
MyBroadcast.Background_Capture_Process.Start()
Basics of the CallBack Method:
public shared My_Process_Enabled as boolean
Public Sub Capture_Process()
While My_Process_Enabled
Try
For MyLoop = 0 To 5
Next
Debug.WriteLine(" Done:" & TimeOfDay)
Application.DoEvents()
Debug.Flush()
Application.DoEvents()
Threading.Thread.Sleep(Convert.ToInt16(PollingSpee d))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End While
End Sub 3 1673
Using Thread.Sleep to control the time methods are executed is going to get
you in trouble. Have you tried the System.Threading.Timer class? Also,
calling Application.DoEvents is *rarely* a good idea (although a thousand and
one other people could explain why better than me).
Although the below provides code smaples in C#, it is becoming a standard
text on the ngs, and is very good: http://www.yoda.arachsys.com/csharp/threads/
Hope this helps
Dan
"gregory_may" wrote: I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some times, its right away, some times after 10 seconds. I have included the setup of the process and the outline of the Call Back Method.
As posted, the callback method can be mildly erratic (only doing a debug.writeline) I am guessing up to an 80% variance on the time it takes to print the Debug messages with an average variance of about 15%-25%. It gets even worse when I add in the real program logic with up to 300% variance on the loop timing.
If I stop & start the thread, it always clears up the timing for a few seconds. Then its back to its crazy erratic self.
I think it makes since to try this on another box, but I need to know if my approach is a good one or if I am doing something wildly silly to start with.
Thanks!
Setting up the Process: MyBroadcast = New BroadcastClass(Broad_IPAddress, Convert.ToInt16(Broad_Port), PollingDelay, BroadcastInterleaveDelay)
MyBroadcast.Background_Capture_Process = New System.Threading.Thread(AddressOf MyBroadcast.Capture_Process)
MyBroadcast.My_Process_Enabled = True
MyBroadcast.Background_Capture_Process.Start()
Basics of the CallBack Method: public shared My_Process_Enabled as boolean
Public Sub Capture_Process() While My_Process_Enabled
Try For MyLoop = 0 To 5
Next
Debug.WriteLine(" Done:" & TimeOfDay)
Application.DoEvents()
Debug.Flush()
Application.DoEvents()
Threading.Thread.Sleep(Convert.ToInt16(PollingSpee d))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End While
End Sub
Thanks for the link!
I have had VERY BAD luck with timers. They just can just stop firing for no
good reason. Usually when I start more than 5 or 10.
I was trying with/without doEvents. Didnt seem to affect anything. My hope
was it would let the Debug.Writeline work properly ... no reall effect.
"Dan Kelley" <Da*******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com... Using Thread.Sleep to control the time methods are executed is going to get you in trouble. Have you tried the System.Threading.Timer class? Also, calling Application.DoEvents is *rarely* a good idea (although a thousand and one other people could explain why better than me).
Although the below provides code smaples in C#, it is becoming a standard text on the ngs, and is very good:
http://www.yoda.arachsys.com/csharp/threads/
Hope this helps Dan
"gregory_may" wrote:
I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some times, its right away, some times after 10 seconds. I have included the setup of the process and the outline of the Call Back Method.
As posted, the callback method can be mildly erratic (only doing a debug.writeline) I am guessing up to an 80% variance on the time it takes to print the Debug messages with an average variance of about 15%-25%. It gets even worse when I add in the real program logic with up to 300% variance on the loop timing.
If I stop & start the thread, it always clears up the timing for a few seconds. Then its back to its crazy erratic self.
I think it makes since to try this on another box, but I need to know if my approach is a good one or if I am doing something wildly silly to start with.
Thanks!
Setting up the Process: MyBroadcast = New BroadcastClass(Broad_IPAddress, Convert.ToInt16(Broad_Port), PollingDelay, BroadcastInterleaveDelay)
MyBroadcast.Background_Capture_Process = New System.Threading.Thread(AddressOf MyBroadcast.Capture_Process)
MyBroadcast.My_Process_Enabled = True
MyBroadcast.Background_Capture_Process.Start()
Basics of the CallBack Method: public shared My_Process_Enabled as boolean
Public Sub Capture_Process() While My_Process_Enabled
Try For MyLoop = 0 To 5
Next
Debug.WriteLine(" Done:" & TimeOfDay)
Application.DoEvents()
Debug.Flush()
Application.DoEvents()
Threading.Thread.Sleep(Convert.ToInt16(PollingSpee d))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End While
End Sub
That article was great. Using this code, I was able to track down some
other threads that were causing timing problems. BTW, is there a slicker
way to do the Monitor.Enter/Exit, C# has the "LOCK () {}" Construct.
Thanks!
Public ReadOnly Capture_lock As New Object
......
System.Threading.Monitor.Enter(Capture_lock)
StartTime = TimeOfDay.Now.Millisecond
Debug.WriteLine("Begin:" & TimeOfDay.Now & ":" & StartTime)
StopTime = TimeOfDay.Now.Millisecond
Debug.WriteLine("Done:" & TimeOfDay.Now & ":" & StopTime)
Debug.WriteLine("Elapsed: " & StopTime - StartTime)
System.Threading.Monitor.Exit(Capture_lock)
"gregory_may" <None> wrote in message
news:e1*************@TK2MSFTNGP12.phx.gbl... I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some times, its right away, some times after 10 seconds. I have included the setup of the process and the outline of the Call Back Method.
As posted, the callback method can be mildly erratic (only doing a debug.writeline) I am guessing up to an 80% variance on the time it takes to print the Debug messages with an average variance of about 15%-25%. It gets even worse when I add in the real program logic with up to 300% variance on the loop timing.
If I stop & start the thread, it always clears up the timing for a few seconds. Then its back to its crazy erratic self.
I think it makes since to try this on another box, but I need to know if my approach is a good one or if I am doing something wildly silly to start with.
Thanks!
Setting up the Process: MyBroadcast = New BroadcastClass(Broad_IPAddress, Convert.ToInt16(Broad_Port), PollingDelay, BroadcastInterleaveDelay)
MyBroadcast.Background_Capture_Process = New System.Threading.Thread(AddressOf MyBroadcast.Capture_Process)
MyBroadcast.My_Process_Enabled = True
MyBroadcast.Background_Capture_Process.Start()
Basics of the CallBack Method: public shared My_Process_Enabled as boolean
Public Sub Capture_Process() While My_Process_Enabled
Try For MyLoop = 0 To 5
Next
Debug.WriteLine(" Done:" & TimeOfDay)
Application.DoEvents()
Debug.Flush()
Application.DoEvents()
Threading.Thread.Sleep(Convert.ToInt16(PollingSpee d))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End While
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: S. David Rose |
last post by:
Hello All!
I am new to Python, and wanted to know if I might ask you a question
regarding timing.
I want a main loop which takes photos from 8 different web-cams, each can
be addressed by...
|
by: Norm |
last post by:
I have run into problems from time to time (and this is
one of those times) using visual basic to access an
external database and perform a basic select from
statement. When the table is extremely...
|
by: eyal.susser |
last post by:
I hear rand() is not thread safe. I was using it, foolish man that I
am. But what is meant exactly by unsafe? What can happen? Bizzare
results from rand()? Something worse?
Thanks,
Eyal.
|
by: Droopy |
last post by:
Hi,
I don't understand why sometimes, a loop running in a thread takes
much more time than usual.
I have a thread that must call each 20 ms a C++ unmanaged function.
I made a C++ managed...
|
by: droopytoon |
last post by:
Hi,
I start a new thread (previous one was "thread timing") because I have
isolated my problem.
It has nothing to do with calling unmanaged C++ code (I removed it in a
test application).
I...
|
by: jamie |
last post by:
hey all,
I am attempting to do motion control for
a final project, but I have a concern....
For motion control, timing is everyting,
the better it is, the better it works.
Currently I am...
|
by: Jay |
last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send
text messages to many, many employees via system.timer at a 5 second
interval. Basically, I look in a SQL table (queue) to...
|
by: Jon Slaughter |
last post by:
I'm using Thread and ThreadStart to create a thread for testing purposes and
I do not want to use a pool because the thread exists for the life time of
the app. Eventually I might move on to using...
|
by: Jon Slaughter |
last post by:
Is there any way to start a terminated thread without using a pool or
creating a new thread object?
void counter()
{
clicks = 0;
clock.Start();
while (counterActive)
{
clicks++;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |