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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:13:03+00:00 2026-06-04T07:13:03+00:00

I currently use a valueconverters in XAML to display my viewmodel DateTime fields in

  • 0

I currently use a valueconverters in XAML to display my viewmodel DateTime fields in “x minutes ago” format. I need to have them updated periodically without causing too much overhead. At any one time I have a dozen on screen, and a few dozen off screen. What is the best strategy?

  1. In the constructor of the viewmodel object, have them register themselves to a static ‘ViewRefresher’ that periodically goes through all the objects and fires PropertyChanged handlers, on the registered fields.

  2. Refresh the content/items control objects that are holding my objects

  3. Something else?

I will go ahead and try both approaches above while I wait for answers and report back in case it helps someone else.

Update:
OK, thanks to csteinmueller for putting me on the events path. Much cleaner than registering/deregistering objects. I believe the following strategy should not be leaky.

public class DateTimeC: INotifyPropertyChanged
{
    public DateTime DT {get; set;}
    public event PropertyChangedEventHandler PropertyChanged;

    public DateTimeC(DateTime dt)
    {
        DT = dt;
        ViewRefresher.FiveSecondsTick += () =>
           { PropertyChanged(this, new PropertyChangedEventArgs("DT")); };
    }

}

public delegate void TickHandler();

public static class ViewRefresher
{
    private static DispatcherTimer dt = new DispatcherTimer();
    private static int counter = 0;

    public static event TickHandler FiveSecondsTick;
    public static event TickHandler OneMinuteTick;

    static ViewRefresher()
    {
        dt.Interval = TimeSpan.FromSeconds(5);
        dt.Tick += Tick;
        dt.Start();
    }

    private static void Tick(object sender, EventArgs e)
    {
        if (FiveSecondsTick != null)
            FiveSecondsTick();

        if (counter++ != 12) return;

        counter = 0;

        if (OneMinuteTick != null)
            OneMinuteTick();
    }
}

Would have been nice if I could derive from DateTime directly instead of inlining as a field, but it’s sealed.

UPDATE 2: This does seem to have a memory leak after all. You need to unhook event for DateTimeC to be garbage-collected, or use a weak reference.

  • 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-04T07:13:04+00:00Added an answer on June 4, 2026 at 7:13 am

    I would choose a System.Timer object togehther with your first approach (all ViewModels register to a collection or event in a static class)

    Timer timer;
    AutoResetEvent autoEvent = new AutoResetEvent(true);
    TimerCallback callback = new TimerCallback(MyCallback);
    
    timer = new Timer(callback, autoEvent, new TimeSpan(0), new Timespan(5));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use a C extension library for Python, but it seems to have
I currently use Authlogic in a web-app to handle user authentication, but have now
I currently use a simple convention for my unit tests. If I have a
We currently use LoadRunner for performance testing our web apps, but we also have
I currently use the following code to print a double: return String.format(%.2f, someDouble); This
I currently use Notepad++ for most of my development. I have been checking out
I currently use Strawberry Perl as my primary Perl distribution. However, I have some
I currently use theme_blocks() in a base theme for Drupal 6, and I have
I currently use a Gmail account as my primary email address (myemail@gmail.com). I have
I currently use SQL2008 where I have a stored procedure that fetches data from

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.