using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool abortThread = false;
Thread myThread;
int cnt = 0;
void myThreadFunc()
{
while(!abortThread && !this.IsDisposed)
{
byte[] bytes = new byte[10];// File.ReadAllBytes("example.usb.txt"); // read in report (apparently this is a blocking call)
Thread.Sleep(300);
bytes[1] = (byte)cnt++;
if(!this.IsDisposed)
this.BeginInvoke(new Action<byte[]>(reportReceived), bytes);
}
}
void reportReceived(byte[] report) // this is run in the form thread, so you can access the controls in here if you wanted
{
Text = report[1].ToString();
}
public Form1()
{
InitializeComponent();
// start the thread
myThread = new Thread(myThreadFunc);
myThread.Start();
}
}
}