About Application.Run and Modal form

p33kabo0

New member
Joined
Aug 13, 2008
Messages
1
Programming Experience
1-3
Hello,

I'm new here and I will start by saying greetings everyone here and thanks for ready my post!

I am currently using a multi-threading splash screen that I got from this address: http://www.codeproject.com/KB/cs/apploadingarticle.aspx

I translated to VB.NET without any problems and it works. I think I might not understand something in there and it is the Application.Run()

I am trying right now to show this splash screen in MODAL mode and this code uses Application.Run and I already tried to show my Form using MySplashFrom.ShowDialog() before calling the Application.Run(MySplashForm)

Here's some code of to start my thread:

VB.NET:
Namespace Splasher
Public Class Screen
    Private Shared splash As SplashScreen
    Private Shared thread As Threading.Thread = Nothing

    Private Shared Sub ShowThread()
        splash = New SplashScreen()
        Application.Run(splash)
    End Sub

    Private Shared Sub Show()
        If Not IsNothing(thread) Then Exit Sub

        thread = New Threading.Thread(New ThreadStart(AddressOf ShowThread))
        thread.IsBackground = True
        thread.SetApartmentState(ApartmentState.STA)
        thread.Start()

        thread.Sleep(1000)
    End Sub

    Public Shared Sub Close()
        If IsNothing(thread) Then Exit Sub
        If IsNothing(splash) Then Exit Sub

        Try
            splash.Invoke(New MethodInvoker(AddressOf splash.Close))
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            thread = Nothing
            splash = Nothing
        End Try
    End Sub
End Class
End Namespace
From a program that I want to call my SplashScreen:
VB.NET:
Splasher.Screen.Show()
Events in my form...
Splasher.Screen.Close()

The thing I am trying to explain is that when I got an error in my form that is calling the splash screen and I popup a message box, well, if I am using the TOPMOST property on my SplashScreen form, well my message box is in the back on it and I cannot click on it and I cannot move the SplashScreen. When I don't put the TOP MOST property to True, well, if I click on my window that is not the splash screen, my splashscreen goes in the back ...so I guess the ShowDialog would solve my problems but I cannot use it ...and also, the top most property is always on top as much that I cannot switch to another application without having my splash screen in the center!!!

This splash screen is really good when you load the application, but I want to use it too when I click on a SEARCH button and it pops up while my gathering my data from the database ...this is where my problem is! I would like to use the same one with a parameter (that is already working) but it's only the showModal that I need... or maybe sending my message box by my splashscreen that would be a little bit more complicated ...

Thanks, I know I'm not sure how to really explain all this because I'm not so used to with multi-threading applications.

Philippe
 
Back
Top