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 9056783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:17:36+00:00 2026-06-16T14:17:36+00:00

Firstly, thank you for taking the time out to read this post. I have

  • 0

Firstly, thank you for taking the time out to read this post.

I have a timer class that downloads “Products” from my SQL Database once every 60 seconds. i.e. to check for updated products that may have been edited by other users.

Here’s my class code:

public class GetProducts : INotifyPropertyChanged
    {
        public GetProducts()
        {
            Timer updateProducts = new Timer();
            updateProducts.Interval = 60000; // 60 second updates
            updateProducts.Elapsed += timer_Elapsed;
            updateProducts.Start();
        }

        public ObservableCollection<Products> EnabledProducts
        {
            get
            {
                return ProductsDB.GetEnabledProducts();
            }
        }

        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("EnabledProducts"));
        }

        public event PropertyChangedEventHandler PropertyChanged;

    }

I then bind to this to the tag property of my XAML (WPF) control:

<Page.Resources>
    <!-- Products Timer -->
    <products_timer:GetProducts x:Key="getProducts_timer" />
</Page.Resources>


Tag="{Binding Source={StaticResource getProducts_timer}, Path=EnabledProducts, Mode=OneWay}"

This works really well. The problem I have is that when the Window or Page that the control is hosted in closes, the timer continues to tick away no matter what.

Can anyone suggest a way to stop the ticker once the Page / Control is no longer available?

Thank you again for your time. All help is greatly appreciated.

  • 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-06-16T14:17:37+00:00Added an answer on June 16, 2026 at 2:17 pm

    First start by keeping a reference to the timer:

    private Timer updateProducts;
    public GetProducts()
    {
        updateProducts = new Timer();
        ......
    }
    

    Create another method, StopUpdates, for instance, which when called will stop the timer:

    public void StopUpdates()
    {
         updateProducts.Stop();
    }
    

    Now stop the timer in the OnUnloaded event of the window:

    private void MyPage_OnUnloaded(object sender, RoutedEventArgs e)
    {
        var timer = this.Resources["getProducts_timer"] as GetProducts;
        if (timer != null)
            timer.StopUpdates();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, thank you for your time taken out to read this and please excuse
Firstly, thanks for taking the time to read and possibly comment on this question.
Firstly I have a class signature that looks like this: internal class JobStore :
Firstly, thanks for taking the time to read this and possibly comment on it.
Firstly I would just like to thank everyone for reading this and answering my
Firstly, I know that writing a class to disk is bad, but you should
I'm a little puzzled by proguard. I have this setting in my pom.xml Firstly,
Firstly, an apology for the length of this post. If brevity is the soul
Firstly this is for a simple university project, so time is more important than
Ok, i'd like to firstly make you notice that i have looked for php

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.