Beklager om koden er noe urydding, slik er det nå.
While argumentet synes ikke å fungere som ønskelig?
Kode
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Threading;
namespace testformeg
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private readonly DispatcherTimer _timer = new DispatcherTimer();
public bool pa;
public string ja;
public int i;
private bool _digitalOutputTest;
private void Button_Click(object sender, RoutedEventArgs e)
{
_digitalOutputTest = !_digitalOutputTest;
if (_digitalOutputTest)
{
Thread thread = new Thread(K8055DigitalOutputTest);
thread.Start();
}
}
private void K8055DigitalOutputTest()
{
while (_digitalOutputTest)
{
for (int i = 1; i < 255; i++)
{
Dispatcher.BeginInvoke(new Action(delegate
{
labell.Content = i.ToString();
}));
Thread.Sleep(10);
if (i==249)
{ i = 0; }
}
Dispatcher.BeginInvoke(new Action(delegate
{
labell.Content = ja;
}));
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
_digitalOutputTest = false;
}
private void Window_Closed(object sender, EventArgs e)
{
_digitalOutputTest = false;
Application.Current.Shutdown();
}
}
}
Sist endret av Jegermannen; 29. januar 2020 kl. 15:33.