title: Timer button resetting
body: <p>I am trying to make an auction application for my course.</p>
  
  <pre><code>namespace Auction
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
  
          public MainWindow()
          {
              InitializeComponent();
              GetData("SELECT * FROM Produs");
              btnLogout.Visibility = System.Windows.Visibility.Hidden;
              btnAdd.Visibility = System.Windows.Visibility.Hidden;
              btnBid.Visibility = System.Windows.Visibility.Hidden;
              tb.Visibility = System.Windows.Visibility.Hidden;
  
          }
  
          private void GetData(string SelectCommand)
          {
              SqlConnection conn = new SqlConnection(@"Data Source=ISAAC;Initial Catalog=licitatie;Integrated Security=True");
              conn.Open();
              SqlCommand cmd = new SqlCommand(SelectCommand);
              cmd.Connection = conn;
              SqlDataAdapter sda = new SqlDataAdapter(cmd);
              DataTable dt = new DataTable("prod");
              sda.Fill(dt);
              myGrid.DataContext = dt;
          }
          private void btnLogin_Click(object sender, RoutedEventArgs e)
          {
              Login login = new Login();
              login.Show();
              Close();
  
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              Countdown(30, TimeSpan.FromSeconds(1), cur =&gt; tb.Text = cur.ToString());
          }
          void Countdown(int count, TimeSpan interval, Action&lt;int&gt; ts)
          {
  
              var dt = new System.Windows.Threading.DispatcherTimer();
              dt.Interval = interval;
              dt.Tick += (_, a) =&gt;
              {
                  if (count-- == 0)
                  {
                      MessageBox.Show("You have won this product!");
                      dt.Stop();
                  }
                  else
                      ts(count);
              };
              ts(count);
              dt.Start();
          }
  
          private void btnLogout_Click(object sender, RoutedEventArgs e)
          {
              MainWindow main = new MainWindow();
              main.Show();
              Close();
              MessageBox.Show("You are not logged. Please log in to bid", "Failed", 
                  MessageBoxButton.OK, MessageBoxImage.Information);
  
          }
  
          private void btnAdd_Click(object sender, RoutedEventArgs e)
          {
              Register reg = new Register();
              reg.Show();
              Close();
          }
  
          private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
          {
  
              var grid = sender as DataGrid;
              var selected = grid.SelectedItem;
              if (selected == grid.SelectedItem)
              {
                  btnBid.Visibility = System.Windows.Visibility.Visible;
  
              }
          }
          private void UpdateColumn()
          {
  
          }
      }
  }
  </code></pre>
  
  <p>This is main page you need to login. I read data from database. The problem is when I press bid button many times it is just resetting, but in background is working on. What do I need to do? </p>
  
  <pre><code>    &lt;Window x:Class="Auction.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow"  Height="500" Width="800"&gt;
      &lt;Grid Margin="0,148,0,3" Name="myGrid" Background="#FF00286E"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="29*"/&gt;
              &lt;ColumnDefinition Width="15*"/&gt;
              &lt;ColumnDefinition Width="0*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid HorizontalAlignment="Left" Height="66" Margin="0,-68,0,0" VerticalAlignment="Top" 
                Width="792" Background="#FF00286E" Grid.ColumnSpan="2"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="12*"/&gt;
                  &lt;ColumnDefinition Width="13*"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Button Content="Login" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Bottom" 
                      Width="102" Height="35" Name="btnLogin" Click="btnLogin_Click"&gt;
                  &lt;Button.Template&gt;
                      &lt;ControlTemplate TargetType="Button"&gt;
                          &lt;TextBlock TextDecorations="Underline"  Margin="0,0,0,-19" FontSize="24" 
                                 FontFamily="Verdana" FontWeight="Bold" FontStyle="Italic"&gt;
                      &lt;ContentPresenter /&gt;
                          &lt;/TextBlock&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Button.Template&gt;
              &lt;/Button&gt;
              &lt;Button Content="Logout" Grid.Column="1" HorizontalAlignment="Left" Margin="300,10,0,0" VerticalAlignment="Bottom" 
                      Width="102" Height="35" Name="btnLogout" Click="btnLogout_Click"&gt;
                  &lt;Button.Template&gt;
                      &lt;ControlTemplate TargetType="Button"&gt;
                          &lt;TextBlock TextDecorations="Underline"  Margin="0,0,0,-19" FontSize="24" 
                                 FontFamily="Verdana" FontWeight="Bold" FontStyle="Italic"&gt;
                      &lt;ContentPresenter /&gt;
                          &lt;/TextBlock&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Button.Template&gt;
              &lt;/Button&gt;
          &lt;/Grid&gt;
          &lt;Grid HorizontalAlignment="Left" Height="78" Margin="0,-146,0,0" VerticalAlignment="Top" Width="792" 
                Grid.ColumnSpan="2" Background="#FF98BFD4"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="769*"/&gt;
                  &lt;ColumnDefinition Width="31*"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Label Content="Welcome to Auction Application.  Please Login to bid!" HorizontalAlignment="Center" Margin="44,28,0,0" VerticalAlignment="Top" 
                     Height="40" Width="748" BorderThickness="3" FontSize="18" FontWeight="Bold" FontFamily="Verdana" Background="#FF98BFD4" Grid.ColumnSpan="2"/&gt;
          &lt;/Grid&gt;
          &lt;Button Content="Bid" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,0,0" 
                  VerticalAlignment="Top" Width="103" Height="29" FontSize="20" FontFamily="Verdana" FontStyle="Italic" 
                  FontWeight="ExtraBold" Click="Button_Click" Name="btnBid"/&gt;
  
          &lt;Button Content="Add User" Grid.Column="1" HorizontalAlignment="Left" Margin="10,255,0,0" 
                  VerticalAlignment="Top" Width="103" Height="31" Name="btnAdd" Click="btnAdd_Click"/&gt;
          &lt;DataGrid HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" 
                    Height="298" Width="502" Name="dataGrid1" ItemsSource="{Binding}" 
                    SelectionChanged="DataGrid_SelectionChanged" AlternatingRowBackground="Coral"&gt;
  
          &lt;/DataGrid&gt;
          &lt;TextBox Grid.Column="1" HorizontalAlignment="Left" Height="48" Margin="10,119,0,0" TextWrapping="Wrap" 
                   VerticalAlignment="Top" Width="144" Name="tb" FontSize="20" FontWeight="Bold" FontStyle="Italic" IsReadOnly="True"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>