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

  • SEARCH
  • Home
  • 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 3271244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:42:38+00:00 2026-05-17T18:42:38+00:00

This works, and I can’t imagine how it might cause problems, but visual studio

  • 0

This works, and I can’t imagine how it might cause problems, but visual studio gives me an warning and that makes me sad. I’m just wondering if doing something like this might ever cause problems:

I have a custom timer that acts like a Wait for some number of milliseconds and then execute a function. It looks like this:

Public Class MyTimer
    Inherits Timers.Timer

    Public Event Done()

    Public Sub New(ByVal interval As Double, ByVal repeat As Boolean, ByVal Work As DoneEventHandler)
        Me.AutoReset = Not repeat
    End Sub

    Private Sub ElapsedToDoneConvert() Handles Me.Elapsed
        RaiseEvent Done()
    End Sub
End Class

I use it like this:

Dim Timer as New MyTimer(1000, False, Sub()
                                        ..code..
                                      End Sub)

or

Dim Timer as New MyTimer(1000, True, Sub()
                                        ..code..
                                      End Sub)

The first case waits one seconds and then executes ..code.., the second case executes ..code.. repeatedly every one second.

Now the question: Imagine I have a form with a textbox called TextBox1 on it. Is this safe?

Dim Timer As MyTimer
Timer = New MyTimer(1000, True, Sub()
                                   If TextBox1.Text <> String.Empty Then
                                      MsgBox("TextBox1 is no longer empty")
                                      Timer.Stop()
                                   End If
                                End Sub)

(So, every one second, Timer checks if TextBox1 is empty. If it isn’t, it displays a message box and stops checking.)

I get a warning that Timer is used before it has been assigned a value, but it is used in the statement that assigns its value. The timer’s interval is required to be greater than zero. Is there anything about this that I don’t understand that could cause problems?

Thanks for the help!

  • 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-17T18:42:39+00:00Added an answer on May 17, 2026 at 6:42 pm

    The problem is that you’re using Timer in a lambda that you pass to the MyTimer constructor. When it compiles this line:

    Timer = New MyTimer(1000, True, Sub()
                                       If TextBox1.Text <> String.Empty Then
                                          MsgBox("TextBox1 is no longer empty")
                                          Timer.Stop()
                                       End If
                                    End Sub)
    

    The Timer instance that you pass in could be used by the MyTimer constructor (the compiler doesn’t know). If that’s the case, and because the constructor runs before the result is assigned to Timer, you’re passing an uninitialized value and you get the warning.

    You can fix it quite easily:

    Dim Timer As MyTimer = Nothing
    Timer = New MyTimer(1000, True, Sub()
                                       If TextBox1.Text <> String.Empty Then
                                          MsgBox("TextBox1 is no longer empty")
                                          Timer.Stop()
                                       End If
                                    End Sub)
    

    That is, explicitly set it to “nothing” first. I think this would work, but in reality, even this is raising alarm bells to me. I would modify the API so that instead of requiring that you pass in an instance of the timer to the callback, you simply change it so that your callback returns either true or false for whether it wants to continue or not. That way, MyTimer itself can be responsible for stopping when the timer returns false.

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

Sidebar

Related Questions

can anybody tell me why this works <g:each var=n in=${com.pp.News.list()}> <h2>${n.t}</h2> <p>${n.tx}</p> </g:each> but
I'm trying to understand how this works but can't figure it out yet. I
I have a Label that looks the following: <Label Name=FalsePositiveInput Content=&#x2713;> This works but
This code works but $vars can't be defined in the call() function. Why do
This works when I have only one state code as a parameter. How can
Can someone explain me why this works: select val1, val2, count(case when table2.someID in
I like how this works in Zend Framework. I can know which environment I'm
I can't figure out why... This works: <?php if($_POST['test']) echo posted; ?> <form method=POST
I created a library bundle for commons-lang3 and this works well. I can build
Can an if statement have more than one then statements? # this works a

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.