Results 1 to 25 of 25

Thread: [RESOLVED] How to put app icon in the TaskBar when the MyApplication_Startup event fires

Threaded View

  1. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    528

    Re: How to put app icon in the TaskBar when the MyApplication_Startup event fires

    Jmc,

    The dedicated splash screen functionality built into the application framework actually creates and displays the splash form on a secondary thread. That's how it is able to be displayed and remain responsive while code is executing in the Startup event handler.
    This is new information for me. Thanks.

    I would like to show the user what’s happening during the app startup, from the Application_Startup event to the first appearance of the main form. I also noted in your post #4 that there’s a couple of MyApplication events that would be useful to use (NetworkAvailabilityChanged and StartupNextInstance).

    If you want the splash form to display information about the progress of the Startup event, you have to communicate across a thread boundary. It's not a big deal but it just means calling Invoke or BeginInvoke to do anything in the splash form. I prefer to do that within the splash form itself, making things easier for code accessing the splash screen. If you're interested, I'll whip up an example.
    An example would be really helpful. I have no experience with cross-thread communications.

    I mentioned that the app checks to see if the back-end database file is present when it starts up. I do this in the Application_Startup event because if the database file is not present, then I notify the user and exit the app. In this scenario, the splash form never appears, just a MessageBox dialog.

    Code:
    '...check back-end database file presence
    If FileIO.FileSystem.FileExists(My.Settings.myDataSource) = False Then
        If IsDebugMode() Then
            Using ofd As New OpenFileDialog
                With ofd
                    .Title = "Please select the data file..."
                    .Filter = "Microsoft Access|*.accdb"
                    .InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory
                    intResult = .ShowDialog()
                End With
                If intResult = DialogResult.Cancel Or ofd.FileName = "" Then
                    '...the user can either select a file and then click Cancel, or click Cancel without selecting a file
                    '   (the OpenFileDialog object will not allow the user to click Open without selecting a file)
                    strMSG = "The application is cannot proceed without a data file (DEBUG mode)." & vbCrLf & vbCrLf &
                        "Goodbye."
                    MessageBox.Show(strMSG, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Environment.Exit(0)
                End If
            End Using
        Else
            strMSG = "The application's data file cannot be found, as shown below:" & vbCrLf & vbCrLf &
                vbTab & System.IO.Path.GetFileName(My.Settings.myDataSource) & vbCrLf & vbCrLf &
                "Please place this file in the application's startup folder, as shown below:" & vbCrLf & vbCrLf &
                System.AppDomain.CurrentDomain.BaseDirectory & vbCrLf & vbCrLf &
                "Restart the application after the data file has been placed in the application's startup folder." & vbCrLf & vbCrLf &
                "Goodbye."
            MessageBox.Show(strMSG, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Environment.Exit(0)
        End If
    End If
    In a similar way, I'm going to take a look at the MyApplication's NetworkAvailabilityChanged and StartupNextInstance events and exit the app if there is no Internet connection or if the app is already running.

    Thanks again for your help.
    Last edited by Mark@SF; Apr 23rd, 2020 at 08:07 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width