Hello
I created the following project to show you guys how I plan to do things. But my main project will be bigger and will have multiple classes. I'm just trying to get this to work properly so I know I'm using good practice when coding.
ok, lets begin :), so my form has a button called "button1" and a text box called "textBox1" and I have a class called "Class1" which has a method "testtest()", I just put Thread.Sleep in the testtest method so I can find out its running on another thread.
Here is my form code
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;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void Class1Deligate();
private void button1_Click(object sender, EventArgs e)
{
Class1 c = new Class1();
Class1Deligate testMethod = new Class1Deligate(c.testtest);
testMethod.BeginInvoke(endTestMethod, testMethod);
}
void endTestMethod(IAsyncResult ar)
{
}
}
}
and here is my Class one code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Test
{
class Class1
{
public void testtest()
{
Thread.Sleep(8888);
MessageBox.Show("Done");
}
}
}
Am I creating a new thread correctly? And can someone please tell me how to update textbox1 from the testtest method in class1 while its running? I made a earlier post and I was told to use Dispatcher, but for some reason it seems the Dispatcher class is not available for me.
Best Regards!