sasa lazic

sasa lazic

  • NA
  • 104
  • 49.8k

C# android timer dont work

Jul 5 2013 1:59 PM
I try to make timer in android app.
This is code.
Doesn't work

public class Activity1 : Activity
    {
        int count = 1;
        TextView txv1;
        System.Timers.Timer t1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
           // Button button = FindViewById<Button>(Resource.Id.MyButton);

            txv1 = FindViewById<TextView>(Resource.Id.textView7);
            DateTime dt = DateTime.Now;
            //txv1.Text = dt.ToShortTimeString();
            txv1.Text = dt.ToLongTimeString();
            t1 = new System.Timers.Timer(100);
            t1.Elapsed += new ElapsedEventHandler(OnTimeEvent);
            //t1.Interval = 100;
            t1.Enabled = true;
            t1.Start();
        }
        private void OnTimeEvent(object source, ElapsedEventArgs e)
        {
            txv1.Text = count.ToString();
            count++;
        }

I need help.

Thanks

Answers (1)