0

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++;
            }
        }
    }
}
  • The proper way to build a keylogger is to capture the key messages, possibly with a low level hook, polling for them is always a bad idea and will fail here and there eventually. – Michael Puckett II Apr 04 '17 at 00:58
  • Also, your background worker is trying to update a label. This is a threading issue. You should pass the label.Content back to the UI thread for processing. With a background working you need to capture the data, and once complete, use that data back on the UI thread to update UI elements. – Michael Puckett II Apr 04 '17 at 01:00

0 Answers0