473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Timer Help

Hi,

I need to use a Timer at run time. I have created a Timer
class which has method 'CreateTimer'.

I am able to create a timer and run the associated event
(code snippet follows), but I am unable to:

1. Stop this timer.
2. Give it a specific Name (sTimer), so that I can
control its interval dynamically.

Can you Please point out what I am missing in my logic ?
Public Function CreateTimer(ByVal sTimer As string)

Dim TB As Timer

Try

TB = New Timer

TB.Enabled = True
TB.Interval = 3000 '3 seconds delay
TB.Start()
AddHandler TB.Tick, AddressOf TimerEvents01

....

End Function

Private Sub TimerEvents01(ByVal sender As Object, ByVal e
As EventArgs)

Msgbox "Testing" & Now
End Sub
Regards

Vinay
Nov 20 '05 #1
4 2290
"vinay" <cu****@cursor.com> wrote in news:0b9401c38109$c2b9c870
$a*******@phx.gbl:
1. Stop this timer.
Why can you set the timer's Enabled property to False?
2. Give it a specific Name (sTimer), so that I can
control its interval dynamically. Public Function CreateTimer(ByVal sTimer As string)

It looks like you have forgotten to set your return type. If you want to
return the timer from the code:

Public Function CreateTimer(ByVal sTimer As string) As Timer
Dim TB As Timer

Try

TB = New Timer

TB.Enabled = True
TB.Interval = 3000 '3 seconds delay
TB.Start()
AddHandler TB.Tick, AddressOf TimerEvents01
I would recommend setting the handler BEFORE enabling the timer.

....

End Function

Private Sub TimerEvents01(ByVal sender As Object, ByVal e
As EventArgs)

Msgbox "Testing" & Now
End Sub


Make sure you have Option Strict On

Chris
Nov 20 '05 #2
"vinay" <cu****@cursor.com> schrieb
Hi,

I need to use a Timer at run time. I have created a Timer
class which has method 'CreateTimer'.

I am able to create a timer and run the associated event
(code snippet follows), but I am unable to:

1. Stop this timer.
Call the Stop method or set Enabled = False
2. Give it a specific Name (sTimer), so that I can
control its interval dynamically.

Can you Please point out what I am missing in my logic ?
Public Function CreateTimer(ByVal sTimer As string)

What do you expect the function to return?

Dim TB As Timer

Try

TB = New Timer

TB.Enabled = True
TB.Interval = 3000 '3 seconds delay
TB.Start()
AddHandler TB.Tick, AddressOf TimerEvents01

....

End Function

Private Sub TimerEvents01(ByVal sender As Object, ByVal e
As EventArgs)

Msgbox "Testing" & Now
End Sub

Don't know if it helps:

Private m_Timer As Timer

Sub CreateTimer()

m_Timer = New Timer

m_Timer.Interval = 3000 '3 seconds delay
m_Timer.Start()
AddHandler m_Timer.Tick, AddressOf TimerEvents01

End Sub

Sub KillTimer
RemoveHandler m_Timer.Tick, AddressOf TimerEvents01
m_Timer.Stop
End Sub
Maybe you also want to add a Name property:

Public ReadOnly Name As String

Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
--
Armin

Nov 20 '05 #3
Cor
Hi Vinay,
Take a look at Timer which Timer you are using, there are at least 3 and
they are all very different
Microsoft.VisualBasic.Timer
Windows.Forms.Timer
System.Threading.Timer
I thought that the last one was almost not to stop because he has his own
thread
(I am not sure of that)
Cor
Nov 20 '05 #4
"Chris Dunaway" <du******@lunchmeatsbcglobal.net> schrieb
Dim TB As Timer

Try

TB = New Timer

TB.Enabled = True
TB.Interval = 3000 '3 seconds delay
TB.Start()
AddHandler TB.Tick, AddressOf TimerEvents01


I would recommend setting the handler BEFORE enabling the timer.


I wanted to suggest the same but as it is a System.Windows.Forms.Timer, the
first tick event does not occur before the app is idle, so it's not really
required to add the handler before.
--
Armin

Nov 20 '05 #5

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

Similar topics

9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
2
by: Alfonso Morra | last post by:
Hi, I am writing a timer class that I want to be able to get to notify me (via a callback func), when a specified interval has elapsed. I have most of the timer functionality figured - however,...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
7
by: Mike Eaton | last post by:
Hi All, I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user...
7
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...
9
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
5
by: PulkitZery | last post by:
Hello Everyone, I need some help here, I have a form on which I have all the user interface components, and I need to do a big calculation every 5 seconds. I used the Timer object to do this...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.