473,473 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

My Turn - Threading

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

--
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))
--

Nov 21 '05 #1
10 1064
Instead of "stop" try "sleep".

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:#2**************@TK2MSFTNGP12.phx.gbl:
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


Nov 21 '05 #2
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.

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

--
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))
--

Nov 21 '05 #3
Imran was correct, but thanks for answering

--
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" <ad***@nospamherekjmsolutions.com> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
Instead of "stop" try "sleep".

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:#2**************@TK2MSFTNGP12.phx.gbl:
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

Nov 21 '05 #4
Bang On - I just didnt see it ( What an idiot I am )

Thanks

--
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))
--
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
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.

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
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

--
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))
--


Nov 21 '05 #5
Do we get it when it is ready?

Cor
Nov 21 '05 #6
good question Cor :)

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do we get it when it is ready?

Cor

Nov 21 '05 #7
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uQ****************@TK2MSFTNGP10.phx.gbl...
Bang On - I just didnt see it ( What an idiot I am )


naah - maybe you just a little break :)
Nov 21 '05 #8
LOL, for what its worth, yes, i would be happy to post it.

--
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))
--
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Oj*************@TK2MSFTNGP09.phx.gbl...
good question Cor :)

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do we get it when it is ready?

Cor


Nov 21 '05 #9
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**************@TK2MSFTNGP12.phx.gbl:
Imran was correct, but thanks for answering


Nov 21 '05 #10
No thats fine really, Im happy for any input to my posts.

Cheers - OHM

--
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" <ad***@nospamherekjmsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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**************@TK2MSFTNGP12.phx.gbl:
Imran was correct, but thanks for answering

Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
16
by: aurora | last post by:
Hello! Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues...
43
by: dan baker | last post by:
I have a page that gets loaded with a meta-refresh hardcoded so that a few things on the page get updated. its kind of a fake chat board. anyway, what I need to do is turn off the meta-refresh once...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
6
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
3
by: Jamie Risk | last post by:
I'm attempting to improve some serially executing code (that uses the SerialPort class) bogging Windows down when it runs. To do the 'antibogging' I'm following the example from MSDN...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.