Et eksempel hvis det kan få nogen til at forstå mit problem og hjælpe :-)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public delegate void UpdateTextCallback(string message);
Thread thread;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (btnStart.Text == "Start")
{
// Creates a new thread
thread = new Thread(new ThreadStart(TestThread));
thread.IsBackground = true;
thread.Start();
btnStart.Text = "Vent venligst";
btnStart.Enabled = false;
}
else
{
thread.Abort();
btnStart.Text = "Start";
}
}
private void UpdateText(string message)
{
textBox1.Text = message;
}
private void TestThread()
{
for (int i = 0; i <= 1000; i++)
{
Thread.Sleep(1000);
textBox1.BeginInvoke(new UpdateTextCallback(UpdateText), new object[] { i.ToString() });
}
}
}
}
Hvordan skal jeg lave dette, hvis metoden TestThread ligger i sin egen klasse der jo ikke kender textBox1 eller UpdateTextCallback...?