473,791 Members | 3,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al 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(B yVal sender As Object, ByVal e
As EventArgs)

Msgbox "Testing" & Now
End Sub
Regards

Vinay
Nov 20 '05 #1
4 2314
"vinay" <cu****@cursor. com> wrote in news:0b9401c381 09$c2b9c870
$a*******@phx.g bl:
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(ByV al 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(ByV al 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(B yVal 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(ByV al 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(B yVal 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.Interva l = 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.Visua lBasic.Timer
Windows.Forms.T imer
System.Threadin g.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******@lunch meatsbcglobal.n et> 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
7288
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; Let's declare a constant Int32 m_TimePeriod = 10000;
2
1429
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, I need to spawn a new thread to carry out the "time watch" - and I need to do this in a cross platform (Well Linux/Windows) way ... Any help will be much appreciated. The code (snippet) follows below:
10
2710
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 two forms (frmSplash and frmMain) and a code Module setup as my startup object. Here is the code that I have, when I try to run this part of the splash screen form shows and then program terminates. What am I doing wrong? Thanks,
7
2681
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 clicks on it, a clock-in/out form is displayed. My problem is this: I've added a timer to the main module to allow the user to set a time to be reminded that they should clock back in/out. The timer works great (i.e. if it's set to remind you at...
7
6085
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...?
9
2646
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 consider. My question is if i am using timer in my windows service, is there any place where interval related information like interval set used by my
12
5535
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 directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
8
6865
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 never used this timer. I used the documentation from Microsoft as a guide, but I cannot get this timer to work. Protected Overrides Sub OnStart(ByVal args() As String) Dim myTimer As New TimerState()
5
7484
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 calculation every 5 seconds. So far so good, but my calculation takes about 2-3 seconds and because of that it made my form very unresponsive for that period of time, which is never acceptable. I googled the problem and found that If I use...
11
2608
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 library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
0
9669
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
9517
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
10428
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
9030
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
7537
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
6776
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
5435
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2916
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.