473,883 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stable Thread Timing?

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, BroadcastInterl eaveDelay)

MyBroadcast.Bac kground_Capture _Process = New
System.Threadin g.Thread(Addres sOf MyBroadcast.Cap ture_Process)

MyBroadcast.My_ Process_Enabled = True

MyBroadcast.Bac kground_Capture _Process.Start( )


Basics of the CallBack Method:
public shared My_Process_Enab led as boolean

Public Sub Capture_Process ()

While My_Process_Enab led

Try

For MyLoop = 0 To 5

Next

Debug.WriteLine (" Done:" & TimeOfDay)

Application.DoE vents()

Debug.Flush()

Application.DoE vents()

Threading.Threa d.Sleep(Convert .ToInt16(Pollin gSpeed))

Catch ex As Exception

Debug.WriteLine (ex.Message)

End Try

End While

End Sub
Nov 21 '05 #1
3 1703
Using Thread.Sleep to control the time methods are executed is going to get
you in trouble. Have you tried the System.Threadin g.Timer class? Also,
calling Application.DoE vents 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_ma y" 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, BroadcastInterl eaveDelay)

MyBroadcast.Bac kground_Capture _Process = New
System.Threadin g.Thread(Addres sOf MyBroadcast.Cap ture_Process)

MyBroadcast.My_ Process_Enabled = True

MyBroadcast.Bac kground_Capture _Process.Start( )


Basics of the CallBack Method:
public shared My_Process_Enab led as boolean

Public Sub Capture_Process ()

While My_Process_Enab led

Try

For MyLoop = 0 To 5

Next

Debug.WriteLine (" Done:" & TimeOfDay)

Application.DoE vents()

Debug.Flush()

Application.DoE vents()

Threading.Threa d.Sleep(Convert .ToInt16(Pollin gSpeed))

Catch ex As Exception

Debug.WriteLine (ex.Message)

End Try

End While

End Sub

Nov 21 '05 #2
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*******@disc ussions.microso ft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Using Thread.Sleep to control the time methods are executed is going to
get
you in trouble. Have you tried the System.Threadin g.Timer class? Also,
calling Application.DoE vents 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_ma y" 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, BroadcastInterl eaveDelay)

MyBroadcast.Bac kground_Capture _Process = New
System.Threadin g.Thread(Addres sOf MyBroadcast.Cap ture_Process)

MyBroadcast.My_ Process_Enabled = True

MyBroadcast.Bac kground_Capture _Process.Start( )


Basics of the CallBack Method:
public shared My_Process_Enab led as boolean

Public Sub Capture_Process ()

While My_Process_Enab led

Try

For MyLoop = 0 To 5

Next

Debug.WriteLine (" Done:" & TimeOfDay)

Application.DoE vents()

Debug.Flush()

Application.DoE vents()

Threading.Threa d.Sleep(Convert .ToInt16(Pollin gSpeed))

Catch ex As Exception

Debug.WriteLine (ex.Message)

End Try

End While

End Sub

Nov 21 '05 #3
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.Threadin g.Monitor.Enter (Capture_lock)

StartTime = TimeOfDay.Now.M illisecond

Debug.WriteLine ("Begin:" & TimeOfDay.Now & ":" & StartTime)

StopTime = TimeOfDay.Now.M illisecond

Debug.WriteLine ("Done:" & TimeOfDay.Now & ":" & StopTime)

Debug.WriteLine ("Elapsed: " & StopTime - StartTime)

System.Threadin g.Monitor.Exit( Capture_lock)

"gregory_ma y" <None> wrote in message
news:e1******** *****@TK2MSFTNG P12.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, BroadcastInterl eaveDelay)

MyBroadcast.Bac kground_Capture _Process = New
System.Threadin g.Thread(Addres sOf MyBroadcast.Cap ture_Process)

MyBroadcast.My_ Process_Enabled = True

MyBroadcast.Bac kground_Capture _Process.Start( )


Basics of the CallBack Method:
public shared My_Process_Enab led as boolean

Public Sub Capture_Process ()

While My_Process_Enab led

Try

For MyLoop = 0 To 5

Next

Debug.WriteLine (" Done:" & TimeOfDay)

Application.DoE vents()

Debug.Flush()

Application.DoE vents()

Threading.Threa d.Sleep(Convert .ToInt16(Pollin gSpeed))

Catch ex As Exception

Debug.WriteLine (ex.Message)

End Try

End While

End Sub

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1829
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 http://ip-addr/image.jpg. That's the easy part, but I want to have 2 cameras poll 3-times a second, 4 cameras poll 2 times a second, and the remaining 2 cameras poll once a second. I have found lots of info suggesting the use of threads for this, all...
2
2549
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 large and performance low, the application freezes. It seems that it is timing out. Recently I was trying to hit an oracle database and got the same problem. In this case, I query a view. When I query a view on a large database, the progam...
7
7379
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.
7
2778
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 wrapper for calling this function from C# (see below _serialChannel.ItTask ()). It works great but for this timing problem. Here below, the main loop for this thread :
16
3318
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 have a thread "_itTaskThread" running. The application is listening on a TCP port. It accepts 2 connection from a client. I simulate a crash on the client side (using "Debug->StopDebugging").
7
3775
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 trying to use the timer function block to do a 10ms loop, but if I remember correctly.... that timing
15
2589
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
9
4011
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 pools but at this point I'm just testing some timing issues. in any cause the thread is simply a counter, static void counter()
11
3813
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++;
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9798
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11164
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10422
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.