Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

timer reset

$
0
0

I have an auction application. my timer is set to go 10 seconds. problem is when i press 2 or 3 times timer are not reset.

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            UpdateColumn();
            Countdown(10, TimeSpan.FromSeconds(1), cur => tb.Text = cur.ToString());
        }
        private void UpdateColumn()
        {
                DataTable dt = list1.DataContext as DataTable;
                Double lp = Convert.ToDouble(dt.Rows[0]["Last price"]);
                lp++;
                dt.Rows[0]["Last price"] = lp; 
        }
   
        void Countdown(int count, TimeSpan interval, Action<int> ts)
        {
           
            var dt = new System.Windows.Threading.DispatcherTimer();
            dt.Interval = interval;
            dt.Tick += (_, a) =>
            {
                if (count-- == 0)
                {
                    MessageBox.Show("You have won this product!");
                    dt.Stop();
                }
                else
                    ts(count);
            };
            ts(count);
            dt.Start();
        }

this is my code. thanks


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>