Click here to Skip to main content
15,896,118 members

Show Forms using BackgroundWorker

JoThousand asked:

Open original thread
Hi,

My program has 'applets', so to speak, so I use a string called AppQueue to tell the BackgroundWorker what to do.

I'm using the BackgroundWorker control to open new forms in the background (keeping the main application form responsive) as some of them take a long time to load.

I call FormName.Show() (where FormName is the form's name) in the RunWorkerCompleted event, but the entire application freezes until the forms show. If I use the DoWork event, the form that I want to open freezes and cannot be used, while the rest of the application continues to respond. I read a tutorial that said to use the RunWorkerCompleted event, but it's not working and instead causes the entire application to freeze until the form that's in the AppQueue string loads.

Here's the code:

VB
Private Sub BkgApps_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BkgApps.RunWorkerCompleted
        
If AppQueue = "Prefs" Then
            Prefs.Show()
            Prefs.Focus()
            Prefs.BringToFront()
            Prefs.WindowState = FormWindowState.Normal

ElseIf AppQueue = "Calendar" Then
            cal.Show()
            cal.Focus()
            cal.BringToFront()
            cal.WindowState = FormWindowState.Normal

End If


If there's anything I can do to improve the question please let me know.

Thanks.
Tags: Visual Basic, BackgroundWorker

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900