Timer functionality

Simon Scott 306 Reputation points
2021-02-23T14:26:06.433+00:00

Good afternoon,

Hopefully someone can help me with this.

I simply want to refresh a label via the Timer function to show the current timezone on the PC. This will be changed at regular intervals hence the requirement.

Here is my code...

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    Dim timeZone As System.TimeZone = timeZone.CurrentTimeZone
    Label3.Text = timeZone.DaylightName
    label3.Refresh()

End Sub

On the form load sub i have added this code in...

Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Start()

Why doesn't the label change after 10 seconds when i change the timezone on the PC?

Many thanks
Simon

Developer technologies | .NET | Other
0 comments No comments

Answer accepted by question author

Xingyu Zhao-MSFT 5,381 Reputation points
2021-02-24T02:31:01.373+00:00

Hi @Simon Scott ,
Current time zone is cached, so you need to reset the cached value.
Here's the code you can refer to.

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick  
          
        System.Globalization.CultureInfo.CurrentCulture.ClearCachedData()  
          
        Dim timeZone As System.TimeZone = TimeZone.CurrentTimeZone  
        Label3.Text = timeZone.StandardName  
        Label3.Refresh()  
    End Sub  

Hope it could be helpful.

Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Simon Scott 306 Reputation points
    2021-02-24T08:53:58.997+00:00

    That works, thank you very much :)

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.