Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new in programming, i want to populate property after every minute.
C#
namespace Testing
{
  public partial class Test : Window
  {
    private static Test _instance;

    public static Test GetInstance()
    {
      return _instance;
    }

    public DateTime LastHitTime { get; set; }

    System.Windows.Threading.DispatcherTimer timer1 = new System.Windows.Threading.DispatcherTimer();

    public Test()
    {
      _instance = this;
      InitializeComponent();

      timer1.Tick += new EventHandler(timer1_Tick);
      timer1.Interval = new TimeSpan(0, 0, 1);
      timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      LblOne.Content = LastHitTime.ToString("HH:mm:ss");
    }
  }
}

last hit value get from
C#
namespace Testing
{
  public class Hits : Log
  {
    public void onHit(String text)
    {
      Test ui = Test.GetInstance();
      Action action = () =>
      {
        ui.LastHitTime = System.DateTime.Now;
      };
      Log.DebugFormat("onIncoming: {0}", text);
    }
  }
}

i want to get ui.lasthittime in Test class, plz help me.
Posted
Updated 7-May-14 3:45am
v2
Comments
Sergey Alexandrovich Kryukov 6-May-14 17:15pm    
Why doing so? What should have changed every minute?
—SA
inam2001 6-May-14 17:17pm    
Actualy this is sample programm, actualy i am using log4net so i want some calculation here.
Sergey Alexandrovich Kryukov 6-May-14 17:42pm    
Why doing anything periodically?
—SA

1 solution

C#
namespace Testing{
  public partial class Test : Window{
    private static Test _instance;

    public static Test GetInstance(){
      return _instance;
    }

    public DateTime LastHitTime { get; set; }

    System.Windows.Threading.DispatcherTimer timer1 = new System.Windows.Threading.DispatcherTimer();

    public Test(){
      _instance = this;
      InitializeComponent();

      timer1.Tick += new EventHandler(timer1_Tick);
      timer1.Interval = new TimeSpan(0, 0, 1);
      timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e){
      LblOne.Content = LastHitTime.ToString("HH:mm:ss");
    }
  }
}


namespace Testing{
  public class Hits : Log{
    public void onHit(String text){
      Test ui = Test.GetInstance();
        ui.LastHitTime = System.DateTime.Now;
      Log.DebugFormat("onIncoming: {0}", text);
    }
  }
}
 
Share this answer
 
v2
Comments
Maciej Los 7-May-14 9:12am    
Is it an answer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900