I am currently teaching a vb.net programming class and I am totally new to the VB Net world. I have a student who completed a suspend and resume assignment in the delegates and events unit. I've copied the work below. He has the threads working so they suspend and resume in the proper order but he wants to have the program print "It works!" at the end.
The question is why does the program print "It works!" before the threads even though the command for writeline is at the end of the program? Thank you all for any help you can give
[FONT=Courier New, monospace]ModuleModule1
[FONT=Courier New, monospace]Publicthing1 As System.Threading.Thread = New Threading.Thread(AddressOfecho1)[/FONT]
[FONT=Courier New, monospace]Publicthing2 As System.Threading.Thread = New Threading.Thread(AddressOfecho2)[/FONT]
[FONT=Courier New, monospace]Subecho1()[/FONT]
[FONT=Courier New, monospace]Dimlooped As Integer[/FONT]
[FONT=Courier New, monospace]Forlooped = 1 To 10[/FONT]
[FONT=Courier New, monospace]Iflooped = 5 Then[/FONT]
[FONT=Courier New, monospace]thing2.start()[/FONT]
[FONT=Courier New, monospace]Ifthing1.threadstate = Threading.ThreadState.Running Then[/FONT]
[FONT=Courier New, monospace]thing1.Suspend()[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]Console.WriteLine("Thiswill show up first and last, but not in the middle.")[/FONT]
[FONT=Courier New, monospace]Next[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]Subecho2()[/FONT]
[FONT=Courier New, monospace]Dimlooped As Integer[/FONT]
[FONT=Courier New, monospace]Forlooped = 0 To 5[/FONT]
[FONT=Courier New, monospace]Console.WriteLine("Thisshold be in the middle.")[/FONT]
[FONT=Courier New, monospace]Next[/FONT]
[FONT=Courier New, monospace]Ifthing1.threadstate = Threading.ThreadState.Suspended Then[/FONT]
[FONT=Courier New, monospace]thing1.resume()[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]SubMain()[/FONT]
[FONT=Courier New, monospace]thing1.Start()[/FONT]
[FONT=Courier New, monospace] Console.WriteLine(“ItWorks!”)[/FONT]
[FONT=Courier New, monospace]Console.ReadLine()[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]EndModule[/FONT]
[/FONT]
The question is why does the program print "It works!" before the threads even though the command for writeline is at the end of the program? Thank you all for any help you can give
[FONT=Courier New, monospace]ModuleModule1
[FONT=Courier New, monospace]Publicthing1 As System.Threading.Thread = New Threading.Thread(AddressOfecho1)[/FONT]
[FONT=Courier New, monospace]Publicthing2 As System.Threading.Thread = New Threading.Thread(AddressOfecho2)[/FONT]
[FONT=Courier New, monospace]Subecho1()[/FONT]
[FONT=Courier New, monospace]Dimlooped As Integer[/FONT]
[FONT=Courier New, monospace]Forlooped = 1 To 10[/FONT]
[FONT=Courier New, monospace]Iflooped = 5 Then[/FONT]
[FONT=Courier New, monospace]thing2.start()[/FONT]
[FONT=Courier New, monospace]Ifthing1.threadstate = Threading.ThreadState.Running Then[/FONT]
[FONT=Courier New, monospace]thing1.Suspend()[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]Console.WriteLine("Thiswill show up first and last, but not in the middle.")[/FONT]
[FONT=Courier New, monospace]Next[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]Subecho2()[/FONT]
[FONT=Courier New, monospace]Dimlooped As Integer[/FONT]
[FONT=Courier New, monospace]Forlooped = 0 To 5[/FONT]
[FONT=Courier New, monospace]Console.WriteLine("Thisshold be in the middle.")[/FONT]
[FONT=Courier New, monospace]Next[/FONT]
[FONT=Courier New, monospace]Ifthing1.threadstate = Threading.ThreadState.Suspended Then[/FONT]
[FONT=Courier New, monospace]thing1.resume()[/FONT]
[FONT=Courier New, monospace]EndIf[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]SubMain()[/FONT]
[FONT=Courier New, monospace]thing1.Start()[/FONT]
[FONT=Courier New, monospace] Console.WriteLine(“ItWorks!”)[/FONT]
[FONT=Courier New, monospace]Console.ReadLine()[/FONT]
[FONT=Courier New, monospace]EndSub[/FONT]
[FONT=Courier New, monospace]EndModule[/FONT]
[/FONT]