Solved

Pause execution of code like msgbox

Posted on 2008-06-20
7
311 Views
Last Modified: 2013-11-06
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
Comment
Question by:koldstar
  • 4
  • 3
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21834135
you have to test for the other thread's .IsAlive property
0
 

Author Comment

by:koldstar
ID: 21834169
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21834207
Well, that depends if you have a way to obtain this thread's reference, some code snippet will be helpful
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:koldstar
ID: 21834278
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
 

Author Comment

by:koldstar
ID: 21834287

private sub encodeAll() 

	for each song in songs

		EncodeSong(song.path)

	next

 end sub

Open in new window

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 21834454
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
 

Author Comment

by:koldstar
ID: 21834609
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now