Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:35:41+00:00 2026-05-17T15:35:41+00:00

I have a custom class written, which I instantiate from an event procedure similar

  • 0

I have a custom class written, which I instantiate from an event procedure similar to

Private Sub EventHandler
    For intForCounter = 1 to intUserEntry
        Dim newObj As New MyClass
        newObj.Property
        newObj.Method()
    Next
End Sub

The class itself looks something like this

Public Property Time As Date
'First attempt:
Dim tmeExec As New Timer
Public Sub Method()
    'Second Attempt
    Dim tmeExec As New Timer
    'A bunch of code for converting a timespan to milliseconds and storing that in intInterval
    With tmeExec
        .Enabled = True
        .Interval = intInterval
    End With
    AddHandler tmeExec.Tick, AddressOf TickHandler
End Sub

Private Sub TickHandler(ByVal myObj As Object, ByVal myArgs As EventArgs)
    Dim tmeSender As Timer = CType(myObj, Timer)
    tmeSender.Stop()
    'Some code here to do something
End Sub

When I had the time placement in the location ‘First Attempt’, everything fired at the last interval specified.

My expectation is that each time a new object is instantiated, a new timer would have been instantiated with it, and so putting the instantiation in the class would be the right way to go. That’s not the case.

But I want to know why it behaves as it does. It’s fine to know HOW something works, but if you know WHY something works, you don’t make that goof again. I asked my professor, but didn’t really understand his answer as fully as I’d like to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:35:41+00:00Added an answer on May 17, 2026 at 3:35 pm

    If you place the instantiation of the Timer outside the Method (at ‘First attempt’), then you only have a single timer. Each time you call Method(), you are just setting the properties of the existing timer and adding a new event handler to the existing timer.

    By moving the Timer instantiation into the Method(), then each time Method() is called, a new Timer object is created.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have a custom class loader which extends from a URLClassLoader. I added a
I have a class derived from TreeviewItem(Custom TreeViewItem) which is used by a class
I have a custom UI control which has a JavaScript class written around the
I have written a custom preference class which contains a simple progress bar in
I have a custom class say 'MyCanvas' derived from wpf Canvas class. MyCanvas has
I have a custom class named CatalogItem which I receive in a method, as
In my iPad App, I have one custom class inherited from UIButton. I am
I have a custom UIImageView class which I use to handle multi-touch events on
I have a custom exception class which contains some additional fields. I want these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.