473,378 Members | 1,415 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,378 software developers and data experts.

destroy instances...

Hi, there is sth i am not sure, i looked at the help in vb.net for creating
timer on the fly (see below).

Since the event would happen 10sec later, I cannot destroy the timer right
away (or can I? or will VB.net destroy automatically?), I can do it after
the event is fired, but the timer is not in scope in the event subroutine.
If I leave it as is, if the application continue to fire the timer over
time, then it would continue to consume system resource?
Public Shared Sub Main()
' Create a new Timer with Interval set to 10 seconds.
Dim aTimer As New System.Windows.Forms.Timer(10000)
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
aTimer.Enabled = True

Console.WriteLine("Press 'q' to quit the sample.")
While Console.Read() <> CInt("q")
End While
End Sub

' Specify what you want to happen when the event is raised.
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub
Nov 21 '05 #1
3 1490
If you want the timer to stop "firing" just do a

Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
dim aTimer as Timer
aTimer = DirectCast(Source, Timer)
aTimer.Enabled = False
End Sub

This will stop it from firing until it is enabled again.

Is this what you need?
Chris
"anthony" <an*******@controlengineer.com> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Hi, there is sth i am not sure, i looked at the help in vb.net for
creating
timer on the fly (see below).

Since the event would happen 10sec later, I cannot destroy the timer right
away (or can I? or will VB.net destroy automatically?), I can do it after
the event is fired, but the timer is not in scope in the event subroutine.
If I leave it as is, if the application continue to fire the timer over
time, then it would continue to consume system resource?
Public Shared Sub Main()
' Create a new Timer with Interval set to 10 seconds.
Dim aTimer As New System.Windows.Forms.Timer(10000)
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
aTimer.Enabled = True

Console.WriteLine("Press 'q' to quit the sample.")
While Console.Read() <> CInt("q")
End While
End Sub

' Specify what you want to happen when the event is raised.
Private Shared Sub OnTimedEvent(source As Object, e As
ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub

Nov 21 '05 #2
Anthony,

Mostly with the form timer is the first thing I do in the tick event is
setting the timer off
And because you did create it in your sub main it can be like this. Typed in
this message so watch typos.

\\\
directcast(sender,windows.forms.timer).enabled = false
///
Why did you use that word "source" where sender is standard?

I hope this helps?

Cor

"anthony" <an*******@controlengineer.com>
Hi, there is sth i am not sure, i looked at the help in vb.net for
creating
timer on the fly (see below).

Since the event would happen 10sec later, I cannot destroy the timer right
away (or can I? or will VB.net destroy automatically?), I can do it after
the event is fired, but the timer is not in scope in the event subroutine.
If I leave it as is, if the application continue to fire the timer over
time, then it would continue to consume system resource?
Public Shared Sub Main()
' Create a new Timer with Interval set to 10 seconds.
Dim aTimer As New System.Windows.Forms.Timer(10000)
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
aTimer.Enabled = True

Console.WriteLine("Press 'q' to quit the sample.")
While Console.Read() <> CInt("q")
End While
End Sub

' Specify what you want to happen when the event is raised.
Private Shared Sub OnTimedEvent(source As Object, e As
ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub

Nov 21 '05 #3
"anthony" <an*******@controlengineer.com> schrieb:
Public Shared Sub Main()
' Create a new Timer with Interval set to 10 seconds.
Dim aTimer As New System.Windows.Forms.Timer(10000)


MSDN on 'System.Windows.Forms.Timer':

---
Implements a timer that raises an event at user-defined intervals. This
timer is optimized for use in Windows Forms applications and must be used in
a window.
---

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

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

Similar topics

2
by: Rob | last post by:
My first GUI so be gentle... When I start my program I call a class that runs the initial window. While in this class if a certain button is pressed it calls a function outside the class. This...
6
by: max(01)* | last post by:
hi people. when i create a widget, such as a toplevel window, and then i destroy it, how can i test that it has been destroyed? the problem is that even after it has been destroyed, the instance...
4
by: Christopher Subich | last post by:
I'm building an application involving both twisted and Tkinter. Since twisted co-opts <widget>.mainloop() in its reactor.run(), and since it behaves very badly if the application quits without...
7
by: Claire | last post by:
How do I make sure Ive disposed of my objects please? Ive added interface IDispose to a base class. Ive several sub classes inheriting from this base class. I store one or other of these...
8
by: vvenk | last post by:
Hello: I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and then the system does not work...
2
by: Flavio | last post by:
Hi, I have a miniframe composed mainly of combo boxes, that I need to destroy and recreate multiple time with different choice lists for the combo boxes. My problem is that even after...
3
by: Matt B | last post by:
Subject is probably poorly worded, but bear with me as I describe the situation that has me puzzled. I create "Save" objects from a Save "factory" class. Many different windows access this...
6
by: muppetjones | last post by:
I'm pretty new at this, and I'm trying to figure out how Perl's classes work with signals. Specifically, it doesn't seem that a class's DESTROY function is called when you Ctrl-C the program. I...
3
by: drzoo2 | last post by:
Completely noob question as I am not a programmer but really trying hard to learn Python (Object oriented programming in general). I am writing a program in python that calls a popup window with...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.