none
Can't modify or close SplashScreen. "Threading" error. VStudio 2017. RRS feed

  • Question

  • I added a SplashScreen (from the Project | "Add New Item" menu) to my app, but I can't manipulate it at runtime. ANY attempt to reference it causes the following error:

    System.InvalidOperationException occurred
      HResult=0x80131509
      Message=Cross-thread operation not valid: Control 'SplashScreen1' accessed from a thread other than the thread it was created on.
      Source=<Cannot evaluate the exception source>
      StackTrace:
    <Cannot evaluate the exception stack trace>
    

    It's just a background image in a modal/borderless box with a Timer. In the timer, I coded a 2.5 second delay (I originally wanted it to fade in/out, but ANY attempt to reference the Splash Screen from within it causes the above error.

    I'll try to get the Fade to work later, but for now, I'll settle for a simple "Me.Close()" at the end. When the timer completes, I get the above threading error on my Close statement.

    A Google search was no help. All references are to an earlier version of VS/VB using a modal addon form instead of SplashScreen (which I will attempt next if I can't figure this out.) Very annoying.

    (PS: Then once I get past this, I've got another bug waiting for me: A File/Read loop that won't terminate.)

    TIA

    Thursday, August 24, 2017 12:28 AM

Answers

  • Thx, but I'm a bit confused.

    Assuming you downloaded that and it worked like I said, if you want to effect a "fade-in", then go to code view for "Welcome.vb" and replace what you have in yours with the following:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Welcome
        Private WithEvents tmr As Timer
    
        Private Sub _
            Welcome_Load(sender As System.Object, _
                         e As System.EventArgs) _
                         Handles MyBase.Load
    
            Me.Opacity = 0
    
            tmr = New Timer _
                With {.Interval = 100, _
                      .Enabled = True}
    
            tmr_Tick(Nothing, Nothing)
    
        End Sub
    
        Private Sub _
            tmr_Tick(sender As Object, _
                     e As System.EventArgs) _
                     Handles tmr.Tick
    
            If Me.Opacity = 1 Then
                tmr.Enabled = False
            Else
                Me.Opacity += 0.05
            End If
    
        End Sub
    End Class

    Experiment with the settings and note that I didn't change the overall 5 seconds minimum time.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 3:31 PM

All replies

  • It's just a background image in a modal/borderless box with a Timer. In the timer, I coded a 2.5 second delay (I originally wanted it to fade in/out, but ANY attempt to reference the Splash Screen from within it causes the above error.

    Show the code you are using to access the splash screen. Be sure that you include whatever code is required to get the reference to the instance.

    What sort of timer are you  using?

    Thursday, August 24, 2017 2:31 AM
  • Hi Mugsy_in_Houston,

    Your application is WInform? If yes, Do you have the project's startup form and splash screen set in the project properties?

    the splash screen is not responsible for creating the main form and should not do so.  If you have code that needs to run before the main form is created, while the splash screen is visible, place that code in the application's Startup event.

    Go to the project's property--View application Events--Place some code in the MyApplication_Startup event.

    Best Regards,

    Cherry

     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Frank L. Smith Thursday, August 24, 2017 1:22 PM
    Thursday, August 24, 2017 3:10 AM
    Moderator
  • Thx for the reply.

    I was already working on a project when I decided to add a splash screen. In a separate module, I added a Boolean wait variable so my main program would know once the splash screen was closed ("Application.DoEvents()" inside a Do/Loop till variable is False). Beyond that, they have no connection.

    I added a simple Timer object (Delay 10, Enabled=True) to the SplashScreen form. That is all. I then coded a simple "fade-in, pause, fade out" in the "Tick" event, but any attempt to reference the form itself crashes the program. As a test, I replaced changing "Me.Opacity" with a simple variable. The code still crashed when it reached the "Me.Close()" at the end (leaving off the "Me." didn't work either.)

    Here is my SplashScreen code (all of it):


    Public NotInheritable Class SplashScreen1
        Public Property ApplicationTitle As Object
        Dim bolFadeIn As Boolean = True ' True = Fade In. False = Wait then Fade Out.
        Dim sngOpacity As Single = 0.0  ' Test variable. Was "Me.Opacity"
        Dim sngWait As Single = 1.5     ' seconds.
    
        Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            bolSplashScreen = True
        End Sub
    
        Private Sub tmrFade_Tick(sender As Object, e As EventArgs) Handles tmrFade.Tick
            If bolFadeIn Then sngOpacity += 0.02    ' Fade In
            If sngOpacity >= 1 Then
                bolFadeIn = False                   ' Pause
                sngWait -= 0.02
            End If
            If sngWait <= 0 Then sngOpacity -= 0.02 ' Fade Out
            If sngWait <= 0 And sngOpacity <= 0 Then
    bolSplashScreen = False
    Me.Close() ' Error occurs here.
    End If End Sub End Class

    ANY reference to the form from within the form causes it to crash. :(

    TIA.



    Thursday, August 24, 2017 10:53 AM
  • ANY reference to the form from within the form causes it to crash. :(

    There isn't any code to start the timer, so I can't see how the timer tick event could ever fire, or how the error line could even be reached, so the error doesn't make much sense.

    You should insert a breakpoint at the place in your code where the timer is started, and follow the logic flow by single stepping from that point.

    Thursday, August 24, 2017 11:50 AM
  • Hello,

    Even though there is no code I suspect the issue is with attempting to access a control across threads. Take a look at the following code sample, the project SplashScreenProgress_VB which accesses controls across threads. My code sample may not fit exactly to your project yet the solution may be found conceptually.

    In short, the splashscreen form runs in a different thread (in your project) then the main form and I'm thinking this is your issue.

    In regards to "I've got another bug", if it's unrelated to this issue then please ask in another post.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, August 24, 2017 12:36 PM
    Moderator
  • There isn't any code to start the timer, so I can't see how the timer tick event could ever fire, or how the error line could even be reached, so the error doesn't make much sense.

    You should insert a breakpoint at the place in your code where the timer is started, and follow the logic flow by single stepping from that point.


    Thx for the reply.

    The timer is set to "Enabled = True" at design time, so it starts the moment the program is run.

    I've set a breakpoint in my timer, and it does indeed trigger.

    The program does not crash immediately upon being run. It crashes when "Me.Close()" is executed inside the timer.

    Thursday, August 24, 2017 12:56 PM
  • Cherry is correct.

    Set the .MinimumSplashScreenDisplayTime (in milliseconds):

    https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.minimumsplashscreendisplaytime(v=vs.110).aspx


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 1:23 PM
  • Thanks for the reply.

    I provided the full SplashScreen code above. As noted, the timer is enabled at design time so it runs as soon as the program starts.

    I deleted the "Me.Close()" so there's no error and tried executing "SplashScreen1.Close()" from my Main program once "bolSplashScreen = False", but the SplashScreen does not go away and my program won't continue (breakpoint after the "Close()" IS triggered, but then the code refuses to continue.) I also tried adding "SplashScreen1.tmrFade.Enabled = False" just above the Close but it too didn't help.

    I tried moving the timer and all code to my frmMain and it made no difference. As soon as I try to address "SplashScreen1", crash.

    I'm stuck. Thx.

    Thursday, August 24, 2017 1:25 PM
  • You wrote "In a separate module,".

    It seems that there is a lot of code is wired up. If you use a module, then it runs shared (static in c type languages).  What your error will be is impossible to tell. 

    We have not your eyes you know and now I see only many persons guessing. 

    My guess, The timer is made shared in another module or whatever like that. 


    Success
    Cor

    Thursday, August 24, 2017 1:44 PM
  • Thx, but I'm a bit confused. In Project Properties, I clicked "View Application Events" for Splash_screen and got a "Namespace My" block. At the end (above "End Namespace), I added:

        Public Class MyApplication_Startup
            Public Property MinimumSplashScreenDisplayTime As Single = 1.5
        End Class

    This has no effect on the end result. The SplashScreen still does not close. Any attempt to address it still causes a crash.

    At the link you gave, it says:

    You should set the My.Application.MinimumSplashScreenDisplayTime
    property in a method that overrides the OnInitialize or
    OnCreateSplashScreen method.

    ...that's Greek to me. :(

    In my Project Properties, frmMain is still my Startup form. SplashScreen1 is set in "Splash screen:"

    Thanks for the help.



    Thursday, August 24, 2017 2:06 PM
  • You wrote "In a separate module,".

    It seems that there is a lot of code is wired up. If you use a module, then it runs shared.


    Thx for the reply. I use a Module just to declare some Global variables... which in this case is a Boolean var set to False when it is time for the Splash Screen to close.

    The Timer is added to the SplashScreen form at design time and is not reused anywhere else.


    Thursday, August 24, 2017 2:13 PM
  • Thx, but I'm a bit confused. In Project Properties, I clicked "View Application Events" for Splash_screen and got a "Namespace My" block. At the end (above "End Namespace), I added:

        Public Class MyApplication_Startup
            Public Property MinimumSplashScreenDisplayTime As Single = 1.5
        End Class

    This has no effect on the end result. The SplashScreen still does not close. Any attempt to address it still causes a crash.

    At the link you gave, it says:

    You should set the My.Application.MinimumSplashScreenDisplayTime
    property in a method that overrides the OnInitialize or
    OnCreateSplashScreen method.

    ...that's Greek to me. :(

    In my Project Properties, frmMain is still my Startup form. SplashScreen1 is set in "Splash screen:"

    Thanks for the help.



    This is a simple two form project with one form set up to be a Splash Screen.

    http://www.fls-online.net/VBNet_Forum/08-24-17/Demo_SplashScreenTiming.zip

    If you'll download that zip file then extract it, open it with Visual Studio and follow the prompts to convert it to your version.

    Following that -- run it. The splash screen will display for five seconds. Look in Solution Explorer and you'll see this:

    View the "ApplicationEvents.vb" and you'll see this:

    Namespace My
    
        ' The following events are available for MyApplication:
        ' 
        ' Startup: Raised when the application starts, before the startup form is created.
        ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
        ' UnhandledException: Raised if the application encounters an unhandled exception.
        ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
        ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
        Partial Friend Class MyApplication
            Protected Overrides Function _
                OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
                ' Set the display time to 5000 milliseconds (5 seconds). 
                Me.MinimumSplashScreenDisplayTime = 5000
                Return MyBase.OnInitialize(commandLineArgs)
            End Function
        End Class
    
    
    End Namespace
    
    

    See the 5000 (milliseconds) there? That's the way it was intended to work.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 2:23 PM
  • Also, something else that you might not have read from that link is this: That's the minimum splash screen time; it depends on what else is going on:

    "If the main form finishes initializing in less time than what is specified by this property, the splash screen remains until the requested amount of time passes, at which time the main form is displayed. If your application takes longer to start, the splash screen is closed once the main form becomes active."


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Thursday, August 24, 2017 2:30 PM ...formatting
    Thursday, August 24, 2017 2:29 PM
  • I tried to make your code as it would run until that close. 

    So those who sees this don't see it as something which should be done. 

    However, it simply closes the form. How could we help you if you have so much which you don't show. 


    Success
    Cor


    Thursday, August 24, 2017 2:31 PM
  • Thx, but I'm a bit confused.

    Assuming you downloaded that and it worked like I said, if you want to effect a "fade-in", then go to code view for "Welcome.vb" and replace what you have in yours with the following:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Welcome
        Private WithEvents tmr As Timer
    
        Private Sub _
            Welcome_Load(sender As System.Object, _
                         e As System.EventArgs) _
                         Handles MyBase.Load
    
            Me.Opacity = 0
    
            tmr = New Timer _
                With {.Interval = 100, _
                      .Enabled = True}
    
            tmr_Tick(Nothing, Nothing)
    
        End Sub
    
        Private Sub _
            tmr_Tick(sender As Object, _
                     e As System.EventArgs) _
                     Handles tmr.Tick
    
            If Me.Opacity = 1 Then
                tmr.Enabled = False
            Else
                Me.Opacity += 0.05
            End If
    
        End Sub
    End Class

    Experiment with the settings and note that I didn't change the overall 5 seconds minimum time.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 3:31 PM
  • Thx, but I'm a bit confused.

    This is fun, but I have other things I need to be doing.

    Before we leave this though, there was a reason why I put a Label and a ProgressBar on that other form (Welcome.vb) and all that I've shown now will still work the same way also.

    Let's do this: During that minimum five seconds display time, back in the calling form you have a series of "initializing" steps that have to be done. Maybe it's loading data or reading a large XML file online or whatever.

    I'll emulate that in the following. In "Welcome.vb", go back to code view and change all of your code to the following:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Welcome
        Private _loaded As Boolean = False
    
        Private WithEvents tmr As Timer
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Delegate Sub Signature01(ByVal text As String)
    
        Private Sub _
            UpdateLabelText(ByVal text As String)
    
            With Label1
                If String.IsNullOrWhiteSpace(text) Then
                    .Text = String.Empty
                Else
                    .Text = text
                End If
    
                .Refresh()
            End With
    
        End Sub
    
        Private Delegate Sub Signature02(ByVal progress As Double)
    
        Private Sub _
            UpdateProgressBar(ByVal progress As Double)
    
            With ProgressBar1
                If progress <= 0 Then
                    .Value = 0
                    .Visible = False
                Else
                    .Value = CInt(progress)
                    .Visible = True
                End If
    
                .Refresh()
            End With
    
        End Sub
    
        Public Sub _
            UpdateDisplay(ByVal text As String, _
                          ByVal progress As Double)
    
            If _loaded Then
                If Not String.IsNullOrWhiteSpace(text) Then
                    If Me.InvokeRequired Then
                        Me.Invoke(New Signature01(AddressOf UpdateLabelText), text)
                    Else
                        UpdateLabelText(text)
                    End If
                End If
    
                If progress >= 0 AndAlso progress <= 100 Then
                    If Me.InvokeRequired Then
                        Me.Invoke(New Signature02(AddressOf UpdateProgressBar), progress)
                    Else
                        UpdateProgressBar(progress)
                    End If
                End If
            End If
    
        End Sub
    
        Private Sub _
            Welcome_Load(sender As System.Object, _
                         e As System.EventArgs) _
                         Handles MyBase.Load
    
            With ProgressBar1
                .Minimum = 0
                .Maximum = 100
                .Style = ProgressBarStyle.Blocks
                .Visible = False
            End With
    
            Me.Opacity = 0
    
            tmr = New Timer _
                With {.Interval = 100, _
                      .Enabled = True}
    
            tmr_Tick(Nothing, Nothing)
            _loaded = True
    
        End Sub
    
        Private Sub _
            tmr_Tick(sender As Object, _
                     e As System.EventArgs) _
                     Handles tmr.Tick
    
            If Me.Opacity = 1 Then
                tmr.Enabled = False
            Else
                Me.Opacity += 0.05
            End If
    
        End Sub
    End Class


    And in Form1.vb, modify that as follows:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Form1
        Private WithEvents tmr As Timer
        Private _tickTock As Integer
    
        Private Sub _
            Form1_Load(sender As System.Object, _
                       e As System.EventArgs) _
                       Handles MyBase.Load
    
            tmr = New Timer _
                With {.Interval = 1500, _
                      .Enabled = True}
    
        End Sub
    
        Private Sub _
            tmr_Tick(sender As Object, _
                     e As System.EventArgs) _
                     Handles tmr.Tick
    
            ' Unlike a "normal" form, a splash screen runs on
            ' a different thread (as Karen said earlier) and,
            ' further, we didn't create an instance of it; the
            ' application did.
            ' 
            ' We'll need to access it by casting the instance
            ' that the application created to a "Welcome.vb"
            ' form object. We can then pass information into
            ' it -- through a delegate.
            ' 
            ' The delegate is needed because this is on a
            ' different thread so invoking is needed. For
            ' reference, see this MSDN documentation:
    
            ' https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired(v=vs.110).aspx
    
    
    
            Dim splashScreen As Welcome = _
                DirectCast(My.Application.SplashScreen, Welcome)
    
            _tickTock += 1
    
            Select Case _tickTock
                Case 1
                    If splashScreen IsNot Nothing Then
                        splashScreen.UpdateDisplay("This is step one of three", 33.3333!)
                    End If
    
                Case 2
                    If splashScreen IsNot Nothing Then
                        splashScreen.UpdateDisplay("This is step two of three", 66.6666!)
                    End If
    
                Case 3
                    If splashScreen IsNot Nothing Then
                        splashScreen.UpdateDisplay("This is step three of three", 1)
                    End If
    
                Case Else
                    tmr.Enabled = False
    
                    If splashScreen IsNot Nothing Then
                        splashScreen.UpdateDisplay(Nothing, 0)
                    End If
            End Select
    
        End Sub
    End Class
    

    When you run it, you'll see the "Welcome" form fade in then the progress bar and label will update several times, shortly before it then closes and the code returns to Form1.vb.

    A splash screen form is "just another form", yes -- but remember that it's different in how it's instantiated and remember also that it's on another thread. It has to be on another thread so that it doesn't "lock up" while the main form is initializing.

    *****

    I hope you've found this helpful. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 4:48 PM
  • Thx for the reply.

    While your code works (I was surprised to find no timer object and the only code inside the Namespace), when I applied the same code to my own app, it didn't work (Splash screen displays but never goes away and the code does not continue.)

    Ultimately, I'd like to do a "Fade In, Pause, Fade out", which will require a timer and code somewhere.

    You state below my Main app could be what's preventing the Splash Screen from closing.

    As noted previously, I put "DoEvents()" in a Do loop until a timed event is completed (eventually, this will be the Fade In/Out) early in my frmMain (in Form_Load). When the timed event is done, the flag is set and my Do Loop condition is met, moving onto the next line ("SplashScreen1.Close()"), but it never executes and the code refuses to continue.

    I'll look at your next reply. Thx.



    Thursday, August 24, 2017 5:01 PM
  • How could we help you if you have so much which you don't show.

    Thx for the reply, but my main program is quite large. Too large to post all of it (not that I would reveal proprietary code.)

    It shouldn't matter though. There are no other timers, waiting for the Splash screen to finish is the first "activity" executed by my code, and I've suspended all other activity with DoEvents in a Do/Loop until the Splash Screen fade has completed.

    As shown previously, here is that delay in my frmMain:

    ' Display Splash Screen...
    Do Until Not bolSplashScreen ' Boolean value changed to false when timer completes.
        Application.DoEvents()
    Loop
    SplashScreen1.Close() ' Moved from "Me.Close()" in SplashScreen1. Hit, but never executes.
    

    The only activity above this are some Dim statements and a folder assignment that all execute w/o error.

    Thursday, August 24, 2017 5:15 PM
  • Thx for the reply.

    While your code works (I was surprised to find no timer object and the only code inside the Namespace), when I applied the same code to my own app, it didn't work (Splash screen displays but never goes away and the code does not continue.)

    Ultimately, I'd like to do a "Fade In, Pause, Fade out", which will require a timer and code somewhere.

    You state below my Main app could be what's preventing the Splash Screen from closing.

    As noted previously, I put "DoEvents()" in a Do loop until a timed event is completed (eventually, this will be the Fade In/Out) early in my frmMain (in Form_Load). When the timed event is done, the flag is set and my Do Loop condition is met, moving onto the next line ("SplashScreen1.Close()"), but it never executes and the code refuses to continue.

    I'll look at your next reply. Thx.



    Please make it obvious who you're talking to, but I'm pretty sure that you're talking to me.

    *****

    Fading in isn't a problem so long as the minimum time allows for it; after that though, we don't have any real control over the timing. Please read what I showed about how a splash screen works.

    *****

    If you want to have a welcome form shown and your initialization process isn't all that involved (for time), consider not having a splash screen. Set up a form and as the last thing in the form's .Load event, create a new instance of it and do whatever you want then.

    It's not a "splash screen" and won't work like one at that point.

    Make sense?


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Thursday, August 24, 2017 5:25 PM
  • Great. I integrated your code (with "Namespace" code) and it works (though I had to add a Me.Close() and need to add a Fade Out.)

    But I don't understand why your code can execute "Me.Opacity", Me.Close or any other self-referencing command, but my own could not? :(



    Thursday, August 24, 2017 5:36 PM
  • Great. I integrated your code and it works (though I had to add a Me.Close() and need to add a Fade Out.)

    But I don't understand why your code can execute "Me.Opacity", Me.Close or any other self-referencing command, and my own could not? :(

    I guess you're talking to me...

    *****

    Deal with threading the way it has to be done, but if you want total control, don't use it as a Splash Screen at all. If you set up a constructor, you can pass in timing values and anything else you want.

    A "Splash Screen" is different in how it's created (the application creates it) and how it works for timing (the application controls that, with a minimum that you can set -- as shown earlier).

    If your form's code doesn't take so long to start up, create a "welcome form" instead:

    Using welcome As New Welcome(pass in parameters here)
        welcome.ShowDialog
    End Using

    You can't do that if it's set to be the splash screen though.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, August 24, 2017 5:44 PM
  • I hope you've found this helpful. :)

    Thx. I'll give that code careful review.

    I was able to modify your previous code to Fade In, Pause, then Fade Out & close. I just wish I knew what I did wrong before. :(

    For anyone in the future interested in how I did my fade (SplashScreen1 code shown):

    ' Starting SplashScreen Opacity = 0
    Dim sngPause as Single = 20 ' 2 seconds.
    
    Private Sub tmr_Tick(sender As Object, e As System.EventArgs) Handles tmr.Tick
        If Me.Opacity < 1 And sngPause = 20 Then Me.Opacity += 0.04
        If Me.Opacity >= 1 Then sngPause -= 0.5
        If sngPause <= 0 Then Me.Opacity -= 0.04
        If sngPause <= 0 And Me.Opacity <= 0 Then
           tmr.Enabled = False
           bolSplashScreen = False ' frmMain waits for this before continuing.
           Me.Close()
        End If
    End Sub
    
    ' I placed a transparent picture box over my
    ' SplashScreen so clicking it will close it early.
    
    Private Sub pbxCover_Click(sender As Object, e As EventArgs) Handles pbxCover.Click
        ' Trigger the conditions of completion.
        sngPause = 0
        Me.Opacity = 0
    End Sub

    Now, back to figuring out why my file read loop isn't terminating. I'll start a new thread for that if I get stuck. :D

    (PS: Clicking "Reply" instead of Quote fails to specify why you're replying to. Sorry.)
    Thursday, August 24, 2017 7:04 PM
  • The timer is set to "Enabled = True" at design time, so it starts the moment the program is run.

    Don't do that.  Start the timer in the form loaded event handler.  Starting the timer before the form is loaded is likely the cause of the error.
    Thursday, August 24, 2017 9:23 PM
  • I deleted the "Me.Close()" so there's no error and tried executing "SplashScreen1.Close()" from my Main program once "bolSplashScreen = False", but the SplashScreen does not go away and my program won't continue (breakpoint after the "Close()" IS triggered, but then the code refuses to continue.)

    You can't refer to the form through its class name - it's unreliable, and in particular will not work when threading is involved.

    Thursday, August 24, 2017 9:25 PM
  • The only activity above this are some Dim statements and a folder assignment that all execute w/o error.

    No it's not - the timer in the splash screen is also ticking.    You haven't indicated the type of timer you are using, but it seems to be a Windows Forms timer.  A system timer, created after the splash screen loads (and, of course, only started after it is created) would be a better choice.  However, you also have to be sure that you stop the timer if the form closes.     Generally, this won't matter, except that there is one timer tick event that references the form.   If the form is closed when that happens then there will be an error, and the missing references in the error message could be the indication that the form has already gone away when the error occurs. 

    Thursday, August 24, 2017 9:29 PM
  • However, you also have to be sure that you stop the timer if the form closes.

    So long as the minimum has been set and nothing exceeds that amount of time, the framework will ensure that it's alive. After that, when it goes away is up to the framework too and that's indeterminate.

    Your point is taken though; not mitigating the import of it.

    *****

    I still don't think he needs a splash screen at all though.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Thursday, August 24, 2017 10:00 PM ...reworded
    Thursday, August 24, 2017 9:55 PM
  • The timer is set to "Enabled = True" at design time, so it starts the moment the program is run.

    Don't do that.  Start the timer in the form loaded event handler.  Starting the timer before the form is loaded is likely the cause of the error.


    Thx for the reply. That definitely seems like a likely culprit. I may try putting the old non-functioning code back temporarily to test that theory out.
    Friday, August 25, 2017 12:11 AM