NOTE: This is a repost of Xtreme VB Talk, so that's why there are two posts
Well, hello, I come by to post some C# sharp, so I'll just start of :)
POST2:
I'm declaring a form-wide thread, that I want to activate when there's a keystroke. It works perfectly the first time, but when the moving.Resume(); hits the second time, the MessageBox doesn't show up anymore. I think I'm making a fundamental error in my threading logic, but could someone point it out?
Thread main;
Private void Form1_Load(Object sender, System.EventArgs e)
{
moving = New Thread(New ThreadStart(Run));
moving.Start();
moving.Suspend();
}
Private void Form1_KeyDown(Object sender, System.Windows.Forms.KeyEventArgs e)
{
Thread.Sleep(0);
If(moving.ThreadState==ThreadState.Suspended)
{
moving.Resume();
}
e.Handled = true;
}
Public void Run()
{
MessageBox.Show("Still running");
moving.Suspend();
}
POST2:
I found out that my thread was just stopped after execution
But my question remains: How can I keep it running?
I now have this solution:
If(moving.ThreadState==ThreadState.Stopped)
{
moving = New Thread(New ThreadStart(Run));
moving.Start();
}
But I guess that not too healthy for my overhead, while I'm waiting for the Garbage Collector to come by...