Backgroundwork + progressbar

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
MiztaInsane
VIP - Donator
VIP - Donator
Posts: 13
Joined: Thu Jan 14, 2010 3:39 pm

Backgroundwork + progressbar
MiztaInsane
So I have this code in backgroundwork2.dowork how can i show the progress of this in progressbar2
Code: Select all
Dim myJob As New Job2Convert()
        Dim ms As New MediaServer()
        myJob.pszSrcFile = "C:\Users\Devin\Desktop\Release\test.wmv" 'THE FILE TO CONVERT
        myJob.pszDstFile = "C:\Users\Devin\Desktop\Release\test.avi" 'THE FILENAME TO SAVE IT AS
        myJob.pszDstFormat = "avi" 'FORMAT TO CONVERT TOO
        myJob.pszAudioCodec = "aac" 'AUDIO CODEC TO USE
        myJob.nAudioChannels = 2
        myJob.nAudioBitrate = -1
        myJob.nAudioRate = -1
        myJob.pszVideoCodec = "h264" 'VIDEO CODEC TO USE
        myJob.nVideoBitrate = -1
        myJob.nVideoFrameRate = -1
        myJob.nVideoFrameWidth = -1
        myJob.nVideoFrameHeight = -1
        Dim ret As Boolean = ms.ConvertFile(myJob)
thanks
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

Re: Backgroundwork + progressbar
Harlem9191
Insert the following code into the subroutine you want to start the process. I'm guessing it is a button so put it in the click event.
Code: Select all
Dim Strt As System.Threading.Thread
Strt = New System.Threading.Thread(AddressOf MyThread1)
Strt.Start()
Just copy and paste this and delete your old code:
Code: Select all
Sub MyThread1()
        Dim myJob As New Job2Convert()
        Dim ms As New MediaServer()
        myJob.pszSrcFile = "C:\Users\Devin\Desktop\Release\test.wmv" 'THE FILE TO CONVERT
        myJob.pszDstFile = "C:\Users\Devin\Desktop\Release\test.avi" 'THE FILENAME TO SAVE IT AS
        myJob.pszDstFormat = "avi" 'FORMAT TO CONVERT TOO
        myJob.pszAudioCodec = "aac" 'AUDIO CODEC TO USE
        myJob.nAudioChannels = 2
        myJob.nAudioBitrate = -1
        myJob.nAudioRate = -1
        myJob.pszVideoCodec = "h264" 'VIDEO CODEC TO USE
        myJob.nVideoBitrate = -1
        myJob.nVideoFrameRate = -1
        myJob.nVideoFrameWidth = -1
        myJob.nVideoFrameHeight = -1
        Dim ret As Boolean = ms.ConvertFile(myJob)
End Sub

Should work like a charm. But remember, don't try to update controls when using this code. For example, don't try adding something to a listbox or update a progress bar. If you're trying to do that it gets a little more complicated.
User avatar
MiztaInsane
VIP - Donator
VIP - Donator
Posts: 13
Joined: Thu Jan 14, 2010 3:39 pm

Re: Backgroundwork + progressbar
MiztaInsane
Thank you for your help. how can i show the progress of this in the progressbar?

thanks you again
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

Re: Backgroundwork + progressbar
Harlem9191
You would most likely have to use a background worker instead. Check out this: http://www.java2s.com/Code/VB/GUI/Backg ... erDemo.htm

You would have to do a little rewrite of the code I gave you if you want to use this method. Try to avoid cross-thread errors. They can be a pain..
User avatar
MiztaInsane
VIP - Donator
VIP - Donator
Posts: 13
Joined: Thu Jan 14, 2010 3:39 pm

Re: Backgroundwork + progressbar
MiztaInsane
thanks yeh they can be a pain lol

thanks for your help again hope to return the help someday
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

Re: Backgroundwork + progressbar
Harlem9191
If you have any problems then just post back on here and I will have a look at the code you've got.
6 posts Page 1 of 1
Return to “Coding Help & Support”