473,785 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET Timer and Thread question

Hi,

I was trying to do something in a Thread that starts by a
timer. I turn off the timer at the begining of the thread
incase it fires again when the thread is still running. Then
turn on the timer again before the thread finishes. To my
surprise, the timer never come alive again once it has been
turned of in the thread. To test the problem I made a simple
Windows Form project, put a Beep() in the timer. It supposed
to hear beep beep beep every one seconds, but can only hear
one. Here enclosed my clode below. Any help or suggestions are
really appreciated.

Regards,
Vincent

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal _
e As System.EventArg s) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal _
e As System.EventArg s) Handles Timer1.Tick
Beep()
Dim thr As New Threading.Threa d(AddressOf ProcTest)
thr.Start()
End Sub

Private Sub ProcTest()
Timer1.Enabled = False
'Timer1.Stop()
Timer1.Enabled = True
'Timer1.Start()
End Sub
Nov 20 '05 #1
10 1470
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for your
problem.

Cor
Nov 20 '05 #2
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for your
problem.

Cor
Nov 20 '05 #3
"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:et******** ******@TK2MSFTN GP10.phx.gbl:
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for
your problem.

Cor


Thanks for your suggestion. The System.threadin g.timer works great! Just
curious, I also tried System.timers.t imer, that works as well.

Don't understand why the System.Windows. Forms.Timer has the strange
problem. Maybe it is by design, but why vb.net doesn't give a compile error
or warning something. I wonder if it does the same thing in C#.
Nov 20 '05 #4
"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:et******** ******@TK2MSFTN GP10.phx.gbl:
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for
your problem.

Cor


Thanks for your suggestion. The System.threadin g.timer works great! Just
curious, I also tried System.timers.t imer, that works as well.

Don't understand why the System.Windows. Forms.Timer has the strange
problem. Maybe it is by design, but why vb.net doesn't give a compile error
or warning something. I wonder if it does the same thing in C#.
Nov 20 '05 #5
"Vincent" <Ja***@serbe.co m> schrieb
Hi,

I was trying to do something in a Thread that starts by a
timer. I turn off the timer at the begining of the thread
incase it fires again when the thread is still running. Then
turn on the timer again before the thread finishes. To my
surprise, the timer never come alive again once it has been
turned of in the thread. To test the problem I made a simple
Windows Form project, put a Beep() in the timer. It supposed
to hear beep beep beep every one seconds, but can only hear
one. Here enclosed my clode below. Any help or suggestions are
really appreciated.

Regards,
Vincent

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal _
e As System.EventArg s) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal _
e As System.EventArg s) Handles Timer1.Tick
Beep()
Dim thr As New Threading.Threa d(AddressOf ProcTest)
thr.Start()
End Sub

Private Sub ProcTest()
Timer1.Enabled = False
'Timer1.Stop()
Timer1.Enabled = True
'Timer1.Start()
End Sub


You must access the timer from the thread that created the timer.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
"Vincent" <Ja***@serbe.co m> schrieb
Hi,

I was trying to do something in a Thread that starts by a
timer. I turn off the timer at the begining of the thread
incase it fires again when the thread is still running. Then
turn on the timer again before the thread finishes. To my
surprise, the timer never come alive again once it has been
turned of in the thread. To test the problem I made a simple
Windows Form project, put a Beep() in the timer. It supposed
to hear beep beep beep every one seconds, but can only hear
one. Here enclosed my clode below. Any help or suggestions are
really appreciated.

Regards,
Vincent

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal _
e As System.EventArg s) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal _
e As System.EventArg s) Handles Timer1.Tick
Beep()
Dim thr As New Threading.Threa d(AddressOf ProcTest)
thr.Start()
End Sub

Private Sub ProcTest()
Timer1.Enabled = False
'Timer1.Stop()
Timer1.Enabled = True
'Timer1.Start()
End Sub


You must access the timer from the thread that created the timer.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
Hi Cor,
windows.forms .form.timer Whenever time is elapsed it puts an event in the message queue and
windows will work on one message after one. Suppose you have set timer
interval at 200ms there is not guarantee that it will come to ur
Timertick event at 200 ms

System.timers .timer This runs on the forms thread and also has the accuracy of time so
timertick event will happen after 200 ms
System.thread ing.timer
This runs on a different thread but has the same functionlity as
systems.timer.t ime so we need to be careful while updating the form
variables as windows forms are not thread safe.

Regards
Sobhan

Jabco <Ja***@serbe.co m> wrote in message news:<Xn******* *************** ****@207.46.248 .16>... "Cor Ligthert" <no**********@p lanet.nl> wrote in
news:et******** ******@TK2MSFTN GP10.phx.gbl:
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for
your problem.

Cor


Thanks for your suggestion. The System.threadin g.timer works great! Just
curious, I also tried System.timers.t imer, that works as well.

Don't understand why the System.Windows. Forms.Timer has the strange
problem. Maybe it is by design, but why vb.net doesn't give a compile error
or warning something. I wonder if it does the same thing in C#.

Nov 20 '05 #8
Hi Cor,
windows.forms .form.timer Whenever time is elapsed it puts an event in the message queue and
windows will work on one message after one. Suppose you have set timer
interval at 200ms there is not guarantee that it will come to ur
Timertick event at 200 ms

System.timers .timer This runs on the forms thread and also has the accuracy of time so
timertick event will happen after 200 ms
System.thread ing.timer
This runs on a different thread but has the same functionlity as
systems.timer.t ime so we need to be careful while updating the form
variables as windows forms are not thread safe.

Regards
Sobhan

Jabco <Ja***@serbe.co m> wrote in message news:<Xn******* *************** ****@207.46.248 .16>... "Cor Ligthert" <no**********@p lanet.nl> wrote in
news:et******** ******@TK2MSFTN GP10.phx.gbl:
Hi Vincent,

There are 3 timers
windows.forms.f orm.timer
System.timers.t imer
System.threadin g.timer

The one you are using now is as far as I can see the
windows.forms.f orm.timer and I think not the one the most suitable for
your problem.

Cor


Thanks for your suggestion. The System.threadin g.timer works great! Just
curious, I also tried System.timers.t imer, that works as well.

Don't understand why the System.Windows. Forms.Timer has the strange
problem. Maybe it is by design, but why vb.net doesn't give a compile error
or warning something. I wonder if it does the same thing in C#.

Nov 20 '05 #9
Vincent,
In addition to the others comments, the following recent articles in MSDN
Magazine explain the difference between the three thread objects in .NET &
when to use each.

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

http://msdn.microsoft.com/msdnmag/is...3/default.aspx

Hope this helps
Jay

And yes, C# will exhibit the same basic behavior.

Hope this helps
Jay

"Vincent" <Ja***@serbe.co m> wrote in message
news:Xn******** *************** ***@207.46.248. 16...
Hi,

I was trying to do something in a Thread that starts by a
timer. I turn off the timer at the begining of the thread
incase it fires again when the thread is still running. Then
turn on the timer again before the thread finishes. To my
surprise, the timer never come alive again once it has been
turned of in the thread. To test the problem I made a simple
Windows Form project, put a Beep() in the timer. It supposed
to hear beep beep beep every one seconds, but can only hear
one. Here enclosed my clode below. Any help or suggestions are
really appreciated.

Regards,
Vincent

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal _
e As System.EventArg s) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal _
e As System.EventArg s) Handles Timer1.Tick
Beep()
Dim thr As New Threading.Threa d(AddressOf ProcTest)
thr.Start()
End Sub

Private Sub ProcTest()
Timer1.Enabled = False
'Timer1.Stop()
Timer1.Enabled = True
'Timer1.Start()
End Sub

Nov 20 '05 #10

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

Similar topics

3
3644
by: brian | last post by:
I have an ASP.Net application that uses impersonation. This works fine for accessing/executing the application. However, the app utilizes a timer, that when fired uses the <machine>ASPNET identity. In order to correct this problem I've modified the Machine.config file in the \Microsoft.Net\Framework\v1.1.4322 folder. However, this didn't solve the problem; instead of using the user id and password specified in Machine.Config, the...
5
2142
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a user requests the page, the app first tries to retrieve a feed from cache, if the feed has expired, it goes off and request the file from the web. If create a CacheItemRemovedCallback for each item to automatically re-request an expired...
1
3300
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer objects which all fire into my OnTimer( object state ) function very nicely. I pass in an object "o" on creation of this timer which I subsequently get passed to me in my OnTimer function. Now in the OnTimer function I want to modify the object...
2
2187
by: steve | last post by:
Since System.Threading.Timer uses the threadpool to do its stuff what happens when (a) You try to create a timer and the thread pool is *exhausted* (b) The timer is due to fire AND all threads in the threadpool are blocked (deadlocked maybe)? As a followup qn to this.. (please excuse my ignorance here) Is there one threadpool per process or one threadpool for the *virtual machine* (ie runtime environment, sorry haven't got a diploma...
10
27694
by: Vincent | last post by:
Hi, I was trying to do something in a Thread that starts by a timer. I turn off the timer at the begining of the thread incase it fires again when the thread is still running. Then turn on the timer again before the thread finishes. To my surprise, the timer never come alive again once it has been turned of in the thread. To test the problem I made a simple Windows Form project, put a Beep() in the timer. It supposed to hear beep beep...
8
2738
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a thread to access the database and then displays a modal dialog which allows the user to cancel the task, if it is taking longer than they want, and shows them a display of how long the query has been running so far.
4
5376
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then adds a time stamp to the received event and adds it to a event queue. This works well (therfore not shown here). The queue fills up. Then I used a timer to check every millisecond for new events in the queue and send it to another thread...
7
6083
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
5
12248
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
5
2129
by: John A. Bailo | last post by:
From a Windows service (NET 2.0) I want to launch serveral threads in a for loop that invokes a method using: new Thread(delegate() { myMethod(248);}).Start(); Will those threads stay active even when the service reaches it Service Timer Stop?
0
9480
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
10152
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
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
7500
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
6740
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();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2880
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.