Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Pause execution of code like msgbox

Hi
I would like to pause execution of a script while waiting for another thread to complete. I can't use threading.thread.sleep(xxx) because it sows the script down. What I'm looking for is something that pauses the script the same way a messagebox does:


While Encoder.RunState <> WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
            Me.ToolStripStatusLabel1.Text = "...Waiting for response"
            MsgBox("test")
  End While

Open in new window

0
koldstar
Asked:
koldstar
  • 4
  • 3
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
you have to test for the other thread's .IsAlive property
0
 
koldstarAuthor Commented:
can you explain how to?

I'm not making the tread my self, but it's Microsofts wmencoder that is creating a new thread every time you call the start function.

The above code is in my main thread.
0
 
Jaime OlivaresSoftware ArchitectCommented:
Well, that depends if you have a way to obtain this thread's reference, some code snippet will be helpful
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
koldstarAuthor Commented:
Try something like this:

The sub, encodeAll loops throug a collection of songs. If I don't pause the encoding it starts a new thread for every song witch causes an out of memory exception
Dim WithEvents Encoder As WMEncoder
 
private sub EncodeSong(byval songname as string)
 
 	Encoder = New WMEncoder
 
	'do some stuff with the encoder
	'code removed
	'code removed
 
	Encoder.AutoStop = True
	Encoder.RemoteAdmin = True
     
	Encoder.PrepareToEncode(True)
 
	'start encoding (start a new thread)          
	Encoder.Start()
           
	'pause until process is done
	While Encoder.RunState <> WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
      		Me.ToolStripStatusLabel1.Text = "...Venter på svar!"
      		MsgBox("test")
	End While
end sub
 
private sub encodeAll()
 
	for each song in song
		EncodeSong(song.path)
	next
 
 
end sub

Open in new window

0
 
koldstarAuthor Commented:

private sub encodeAll() 
	for each song in songs
		EncodeSong(song.path)
	next
 end sub

Open in new window

0
 
Jaime OlivaresSoftware ArchitectCommented:
I don't know exactly what you need, do you want to show a messagebox while playing? and hide it after play? You can do something like this:

' Assuming you desing a WaitForm with a message
Dim form as WaitForm = new WaitForm
form.Show()
Me.ToolStripStatusLabel1.Text = "...Venter på svar!"
While Encoder.RunState <> WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
                  Application.DoEvents()  'avoid the application to freeze
End While
form.Hide()
0
 
koldstarAuthor Commented:
No I was trying to get rid of the messagebox. I just wanted something to stop the code, but the Application.DoEvents()  seems to do just fine. thanks :_)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now