Show loading screen in vb.net

I need to show a screen or something like that, saying “Download” or something else while the lengthy process is running.

I am building an application with the Windows Media Encoder SDK, and it takes some time to initialize the encoder. I would like the message “Download” to appear on the screen when it starts the encoder, and then it disappears when the encoder is completed, and they can continue to work with the application.

Any help would be greatly appreciated. Thanks!

+3
source share
3 answers

, "". , ShowDialog(). , , .

, BackgroundWorker . , . :

Imports System.ComponentModel

Public Class LoadingForm ' Inherits Form from the designer.vb file

    Private _worker As BackgroundWorker

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)

        _worker = New BackgroundWorker()
        AddHandler _worker.DoWork, AddressOf WorkerDoWork
        AddHandler _worker.RunWorkerCompleted, AddressOf WorkerCompleted

        _worker.RunWorkerAsync()
    End Sub

    ' This is executed on a worker thread and will not make the dialog unresponsive.  If you want
    ' to interact with the dialog (like changing a progress bar or label), you need to use the
    ' worker ReportProgress() method (see documentation for details)
    Private Sub WorkerDoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
        ' Initialize encoder here
    End Sub

    ' This is executed on the UI thread after the work is complete.  It a good place to either
    ' close the dialog or indicate that the initialization is complete.  It safe to work with
    ' controls from this event.
    Private Sub WorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

End Class

, , :

Dim frm As New LoadingForm()
frm.ShowDialog()

, .

+9

. , , , . X, . .

, , , , , , .

, , .

0

, .

( Mitchel) Application.DoEvents()

Another option you have is to run the initialization code for the encoder in the BackgroundWorker process.

0
source

All Articles