using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace AsynchroneAusfuehrung
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        private async void btnStart_Click(object sender, RoutedEventArgs e)
        {
            int value;

            statusLabel.Content = "Berechnung gestartet";
            textBox1.Clear();

            for (int n = 0; n < 10; n++)
            {
                //value = calculate();
                value = await calculate();
                textBox1.AppendText(value.ToString() + "\n");
            }

            statusLabel.Content = "Berechnung beendet";
        }

        private Task<int> calculate()
        {
            // Simuliere eine längere Berechnung
            Task<int> t = Task.Run(() =>
            {
                Thread.Sleep(1000);
                Random gen = new Random();
                return gen.Next(10);
            });
            return t;
        }


        //private int calculate()
        //{
        //    // Simuliere eine längere Berechnung
        //    Thread.Sleep(1000);
        //    Random gen = new Random();
        //    return gen.Next(10);
        //}
    }
}
