Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET Loading Dialog crashes form

Posted on 2010-09-22
3
Medium Priority
?
443 Views
Last Modified: 2012-05-10
Hi,

I have an application with a main form. On this page when a user click certain labels etc it will show another form, eg Form1. Form1 takes about 20 seconds to load the data in etc, so I have been trying to find a loading dialog. I have found one that is sort of working, but for some reason it crashes the just opened form. Here is the code for the loading form;

Imports System.ComponentModel
Public Class Loading
    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
    Private Sub WorkerDoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
        Form1.Show()
    End Sub
    Private Sub WorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
End Class

Open in new window



On the main page, I have the following code in the label;

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

Open in new window


Now, when I click the Label on the main form, The loading box comes up and works fine. Once the data has finished loading the box disappears, as it should and leaves me with Form1. However Form1 will just hang and crash without any errors after it has been loaded.

Could anyone please help with this code?

Thank you kindly
0
Comment
Question by:DanielBlackmore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 1000 total points
ID: 33733651
The reason is that Form1 has been started from the Loading thread. As the loading thread has finished, Form1 is orphan.

The best solution is that the Loading thread must not open Form1. Form1 must be open from the main form. First, open the Loading thread (that I suppose that shows any kind of "loading" message), and after that open Form1. As the Loading thread executes in it's own thread space, it will show the message anyway.

Hope that helps.
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 1000 total points
ID: 33733725
You open the Form on a different thread so there is no message queue associated with that form. That is the reason your form  hangs around not responding. You will need to change your layout logic so that the form uses the original UI thread with the message queue.
 
0
 

Author Closing Comment

by:DanielBlackmore
ID: 33769978
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Loops Section Overview
Suggested Courses

610 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