Why i have problem in line 'label.Content = licznik++;'.It shows "InvalidOperationException". How works backgroundworker? I wants to count in time my 'licznik'. How can i create program which from start to end it will be check something for example detection my keyboard (keylogger)?
using System;
using System.Collections.Generic;
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.Drawing;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace WpfApplication8
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (obj, ea) => Wykrywanie();
worker.RunWorkerAsync();
}
public void Wykrywanie()
{
int licznik = 0;
for(int i = 0; i <255;i++)
{
label.Content = licznik++;
}
}
}
}