I havent played much with threading and Im testing stuff out with a little
space invaders game. My Invader class has a StopInvader StartInvader and
Invade subs.
There is a class level variable called Alive of Type Boolean.
On StartInvader I begin a new thread at the address of Invade and inside
this While Alive . . . . . . . Do Stuff ( Move etc ) Wend.
Stop invalder simply sets Alive to False.
OK
So the start starts it OK, and it shoots across the screeen, Fine; Stop
Stops the Invade, however, StartInvader only works the first time,
any ideas ? ( Excuse any bad programming as Im only playing )
Public Class Invader
Private invaderImage As Image
Private invaderImageDelete As Image
Private space As Graphics
Private startPoint As Point
Private currentPoint As New Point
Private Enum direction
left
right
End Enum
Private invaderDirection As direction
Private alive As Boolean = True
Private parentForm As Form1
Private invadeThread As Threading.Thread
Public Sub New(ByVal iSpace As Graphics, ByVal refForm As Form1, ByVal
iInvader As String, ByVal iInvaderDelete As String)
space = iSpace
invaderDirection = direction.right
startPoint = New Point(10, 10)
parentForm = refForm
invaderImage = Image.FromFile(iInvader)
invaderImageDelete = Image.FromFile(iInvaderDelete)
End Sub
Public Sub startInvader()
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
parentForm.newGameButton.Enabled = False
parentForm.stopGameButton.Enabled = True
invadeThread = New Threading.Thread(AddressOf invade)
invadeThread.IsBackground = True
invadeThread.Start()
End Sub
Public Sub stopInvader()
parentForm.newGameButton.Enabled = True
parentForm.stopGameButton.Enabled = False
alive = False
End Sub
Private Sub Fire()
End Sub
Private Sub invade()
While alive
If currentPoint.X > space.VisibleClipBounds.Width Then
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
End If
Threading.Thread.CurrentThread.Sleep(20)
space.DrawImage(MyClass.invaderImageDelete, currentPoint)
currentPoint.X += 5
space.DrawImage(MyClass.invaderImage, currentPoint)
End While
End Sub

Signature
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
scorpion53061 - 19 Oct 2004 12:16 GMT
Instead of "stop" try "sleep".
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:#2qj1xctEHA.3156@TK2MSFTNGP12.phx.gbl:
> I havent played much with threading and Im testing stuff out with a little
>
[quoted text clipped - 117 lines]
>
> End Sub
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:12 GMT
Imran was correct, but thanks for answering

Signature
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
> Instead of "stop" try "sleep".
>
[quoted text clipped - 122 lines]
>>
>> End Sub
scorpion53061 - 19 Oct 2004 14:23 GMT
I was just guessing. I didn't have time to pull your code part.
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:uS#dfTdtEHA.1088@TK2MSFTNGP12.phx.gbl:
> Imran was correct, but thanks for answering
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 14:55 GMT
No thats fine really, Im happy for any input to my posts.
Cheers - OHM

Signature
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
>I was just guessing. I didn't have time to pull your code part.
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
> message news:uS#dfTdtEHA.1088@TK2MSFTNGP12.phx.gbl:
>> Imran was correct, but thanks for answering
Imran Koradia - 19 Oct 2004 12:19 GMT
Just a guess - You're setting alive to false when calling StopInvader which
is never being set to true again which is why the second time Invade just
skips the entire while loop. Or did I overlook something :)??
Imran.
>I havent played much with threading and Im testing stuff out with a little
>space invaders game. My Invader class has a StopInvader StartInvader and
[quoted text clipped - 114 lines]
>
> End Sub
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:12 GMT
Bang On - I just didnt see it ( What an idiot I am )
Thanks

Signature
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
> Just a guess - You're setting alive to false when calling StopInvader
> which is never being set to true again which is why the second time Invade
[quoted text clipped - 122 lines]
>>
>> End Sub
Cor Ligthert - 19 Oct 2004 13:34 GMT
Do we get it when it is ready?
Cor
Imran Koradia - 19 Oct 2004 13:47 GMT
good question Cor :)
> Do we get it when it is ready?
>
> Cor
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:49 GMT
LOL, for what its worth, yes, i would be happy to post it.

Signature
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
> good question Cor :)
>
>> Do we get it when it is ready?
>>
>> Cor
Imran Koradia - 19 Oct 2004 13:47 GMT
> Bang On - I just didnt see it ( What an idiot I am )
naah - maybe you just a little break :)