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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:37:38+00:00 2026-05-19T04:37:38+00:00

I am trying to make a class that when it starts it starts a

  • 0

I am trying to make a class that when it starts it starts a stopwatch and all the time the elapsed time is written to a local variable Elapsed which I have a Listview that databinds to. But when I use this code the Listview just displays 00:00:00.00000001 and never changes.
The class’ code is:

namespace project23
{
    public class ActiveEmployee
    {
        public int EmpID { get; set; }
        public string EmpName { get; set; }
        private DateTime date;
        private BackgroundWorker worker;
        public Stopwatch sw;

        public ActiveEmployee(int empID, string empName)
        {
            date = DateTime.Now;
            worker = new BackgroundWorker();
            worker.DoWork += BackgroundWork;
            worker.WorkerReportsProgress = true;

            worker.RunWorkerAsync();
        }

        private TimeSpan elapsed;
        public TimeSpan Elapsed
        {
            get { return elapsed; }
            set
            {
                elapsed = value;
                NotifyPropertyChanged("Elapsed");
            }
        }

        private void BackgroundWork(object sender, DoWorkEventArgs args)
        {
            sw = new Stopwatch();
            sw.Start();
            if(true)
            {
                Elapsed = sw.Elapsed;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}

Now it works using Timers instead

using System;
using System.ComponentModel;
using System.Timers;

namespace Eksamen_Januar_2011 { public class ActiveEmployee : INotifyPropertyChanged { public int EmpID { get; set; } public string EmpName { get; set; } private DateTime startDate; private BackgroundWorker worker; private Timer timer;

public ActiveEmployee(int empID, string empName) { startDate = DateTime.Now; worker = new BackgroundWorker(); worker.DoWork += BackgroundWork; timer = new Timer(1000); timer.Elapsed += TimerElapsed; worker.RunWorkerAsync(); } private TimeSpan elapsed; public TimeSpan Elapsed { get { return elapsed; } set { elapsed = value; NotifyPropertyChanged("Elapsed"); } } private void BackgroundWork(object sender, DoWorkEventArgs args) { timer.Start(); } private void TimerElapsed(object sender, ElapsedEventArgs e) { Elapsed = DateTime.Now - startDate; } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } }

}

  • 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-19T04:37:39+00:00Added an answer on May 19, 2026 at 4:37 am

    You need to implement the INotifyPropertyChanged interface. Modify your class declaration to:

    public class Employee : System.ComponentModel.INotifyPropertyChanged
    

    See http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx.

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

Sidebar

Related Questions

Alright so here is the deal. I am trying to make a application that's
I have a class that implements Runnable and am currently using an Executor as
I'm trying to make a method that will tell me weather or not it
Here is my post: I'm trying to make myself as clear as possible: Description
I have a GUI C# application that has a single button Start/Stop. Originally this
I'm trying to fix a design flaw that I recently ran across in some
I am a mobile web developer and trying to monetize my traffic with mobile
We require programmatic access to a SQL Server Express service as part of our
This is kind of a weird one. I'm looking for ideas on how to
I'm doing some exploration of operator-overloading at the moment whilst re-reading some of my

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.