Answers for "how to end an infinite for loop c#"

C#
-1

how to make infinite loop in c#

for (int a = 0; a < 50; a--)
{
  // Whatever You Want To Do.
}
Posted by: Guest on May-29-2020
0

how to make an infinite loop in c# without breaking the UI

public partial class MainWindow : Window
{
    private readonly System.Timers.Timer _timer;

    public MainWindow()
    {   
        InitializeComponent();

        _timer = new Timer(250); //Updates every quarter second.
        _timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    }

    private void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        ProcessGeneration();
    }

    private void PlayClick_Handler(object sender, RoutedEventArgs e)
    {           
         var enabled = _timer.Enabled;
         if(enabled)
         {
             PlayButton.Content = "Play";
             _timer.Enabled = false;
         }
         else
         {
             PlayButton.Content = "Pause";
             _timer.Enabled = true;
         }
    }

}
Posted by: Guest on November-01-2020

C# Answers by Framework

Browse Popular Code Answers by Language