none
Help. Program keeps running back to the (stopped/disabled) timer. RRS feed

  • Question

  • I added a "splash screen" to my app (using a form instead of the "splash screen" feature) with a timer on it. When the "splash screen" closes, my frmMain loads. In the first lines of its "Form_Load" event, I stop & disable the timer and disable frmSplashScreen (I tried Unloading frmSplashScreen but it didn't help.)

    Moments later in my code, I try to do a FileMove (using various methods), and (during debugging) the first thing the program does is jump back to the timer event in frmSplashScreen.

    Why is it doing this? Is there any way to stop it from happening? TIA


    Friday, May 17, 2019 10:54 PM

Answers

  • Hi

    There must be an exception in Form2 which, since I assume it is not being handled, so it permeates back to the calling code - which is the frmMain.Show() in Form1.

    To verify, try this in the Timer Tick event:

    If Me.Opacity <= 0 Then
        Try
           frmMain.Show()
        Catch ex As Exception
           MessageBox.Show(ex.Message)
        End Try
    End If


    Regards Les, Livingston, Scotland

    Saturday, May 18, 2019 1:23 AM
  • Hi

    I can't reprofuce your issue. Below is the code I tested with,

    The only thing I suspect is that your CopyFile line is throwing an Exception (probably a failure to find the src path)and since it is not handled, would 'jump' back to originating vode (which is where you say it 'jumps' tp)

    I suggest adding a Try ...... Catch around the CopyFile line and MessageBox the exception message in the catch.

    *

    Here is my test code - which works completely normally.

    Option Strict On
    Option Explicit On
    Public Class frmSplash
    	Dim dblTimer As Double = 0.0
    
    	Private Sub frmSplash_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		tmrSplash.Start()
    	End Sub
    
    	Private Sub tmrSplash_Tick(sender As Object, e As EventArgs) Handles tmrSplash.Tick
    		dblTimer += 0.1
    		If dblTimer > 2.0 Then Me.Opacity -= 0.04
    		If Me.Opacity <= 0 Then frmMain.Show()  ' No need to close a form with zero opacity.
    	End Sub
    
    	Private Sub picSplash_Click(sender As Object, e As EventArgs) Handles picSplash.Click
    		Opacity = 0
    	End Sub
    End Class
    Option Strict On
    Option Explicit On
    Public Class frmMain
    	Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		frmSplash.tmrSplash.Stop()
    		frmSplash.tmrSplash.Enabled = False
    		' Must stop timer so DoEvents doesn't run there.
    		frmSplash.Enabled = False
    
    		Dim src As String = "C:\Users\lesha\Desktop\New folder\Plans\Dice 2\11.png"
    		Dim dest As String = "C:\Users\lesha\Desktop\New folder (2)\Dice 2\11.png"
    		My.Computer.FileSystem.CopyFile(src, dest)
    		' Executing this line in the debugger, it instantly jumps back to the Timer even on frmSplashScreen.
    	End Sub
    End Class

    Regards Les, Livingston, Scotland

    Friday, May 17, 2019 11:53 PM

All replies

  • Hi

    You will need to post code. Code from your first 'splash' form, particularly the Timer code and the code that switched to the next form. Then, you will probably need to post the code dfrom the second form load event.

    Please explain what 'and (during debugging) the first thing the program does is jump back to the timer event in frmSplash' actually means. What is first thing.? How do you know it  jumps back to the timer event in frmSplash?


    Regards Les, Livingston, Scotland

    Friday, May 17, 2019 11:04 PM
  • You will need to post code.

    .
    Hey Les, thanks for the reply.

    The SplashScreen's code is pretty simple:

    Public Class frmSplash
        Dim dblTimer As Double = 0.0
    
        Private Sub frmSplash_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            tmrSplash.Start()
        End Sub
    
        Private Sub tmrSplash_Tick(sender As Object, e As EventArgs) Handles tmrSplash.Tick
            dblTimer += 0.1
            If dblTimer > 2.0 Then Me.Opacity -= 0.04
            If Me.Opacity <= 0 Then frmMain.Show()  ' No need to close a form with zero opacity.
        End Sub
    
        Private Sub picSplash_Click(sender As Object, e As EventArgs) Handles picSplash.Click
            Me.Opacity = 0
        End Sub
    End Class

    Then in my frmMain:

    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        frmSplash.tmrSplash.Stop()
        frmSplash.tmrSplash.Enabled = False ' Must stop timer so DoEvents doesn't run there.
        frmSplash.Enabled = False
    
    ...
    
    My.Computer.FileSystem.CopyFile(Src, Dest) ' Executing this line in the debugger, it instantly jumps back to the Timer event on frmSplashScreen.

    Any idea? Thx.


    Friday, May 17, 2019 11:18 PM
  • Try setting the timer to Nothing after issuing Stop method.

    Please remember to mark the replies as answers if they help and unmarked 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.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, May 17, 2019 11:42 PM
    Moderator
  • Hi

    I can't reprofuce your issue. Below is the code I tested with,

    The only thing I suspect is that your CopyFile line is throwing an Exception (probably a failure to find the src path)and since it is not handled, would 'jump' back to originating vode (which is where you say it 'jumps' tp)

    I suggest adding a Try ...... Catch around the CopyFile line and MessageBox the exception message in the catch.

    *

    Here is my test code - which works completely normally.

    Option Strict On
    Option Explicit On
    Public Class frmSplash
    	Dim dblTimer As Double = 0.0
    
    	Private Sub frmSplash_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		tmrSplash.Start()
    	End Sub
    
    	Private Sub tmrSplash_Tick(sender As Object, e As EventArgs) Handles tmrSplash.Tick
    		dblTimer += 0.1
    		If dblTimer > 2.0 Then Me.Opacity -= 0.04
    		If Me.Opacity <= 0 Then frmMain.Show()  ' No need to close a form with zero opacity.
    	End Sub
    
    	Private Sub picSplash_Click(sender As Object, e As EventArgs) Handles picSplash.Click
    		Opacity = 0
    	End Sub
    End Class
    Option Strict On
    Option Explicit On
    Public Class frmMain
    	Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		frmSplash.tmrSplash.Stop()
    		frmSplash.tmrSplash.Enabled = False
    		' Must stop timer so DoEvents doesn't run there.
    		frmSplash.Enabled = False
    
    		Dim src As String = "C:\Users\lesha\Desktop\New folder\Plans\Dice 2\11.png"
    		Dim dest As String = "C:\Users\lesha\Desktop\New folder (2)\Dice 2\11.png"
    		My.Computer.FileSystem.CopyFile(src, dest)
    		' Executing this line in the debugger, it instantly jumps back to the Timer even on frmSplashScreen.
    	End Sub
    End Class

    Regards Les, Livingston, Scotland

    Friday, May 17, 2019 11:53 PM
  • Try setting the timer to Nothing after issuing Stop method.

    .
    Thanks for the suggestion but it had no effect.
    Saturday, May 18, 2019 12:37 AM
  • The only thing I suspect is that your CopyFile line is throwing an Exception (probably a failure to find the src path)

    .
    Thanks for the sample code, but it didn't help.

    The CopyFile isn't throwing an exception.

    I don't know if it matters, but the CopyFile is being executed from a separate Module inside a Sub routine called "ZipFile":

    Public Sub ZipFile(ByVal strDirection As String, Src As String, Dest As String)

    It's called from frmMain:

    ZipFile("X", strPath & "\Temp\archive.zip", "c:\Target") ' eXtract Src Dest

    I could move the entire subroutine from modZip to frmMain but I don't think it would make a difference.

    I don't understand at all why executing a CopyFile command would return to a stopped, disabled timer on a disabled form?



    Saturday, May 18, 2019 1:11 AM
  • Hi

    There must be an exception in Form2 which, since I assume it is not being handled, so it permeates back to the calling code - which is the frmMain.Show() in Form1.

    To verify, try this in the Timer Tick event:

    If Me.Opacity <= 0 Then
        Try
           frmMain.Show()
        Catch ex As Exception
           MessageBox.Show(ex.Message)
        End Try
    End If


    Regards Les, Livingston, Scotland

    Saturday, May 18, 2019 1:23 AM
  • The only thing I suspect is that your CopyFile line is throwing an Exception (probably a failure to find the src path)

    .
    I was wrong. It was indeed throwing an exception (determined by placing the CopyFile in a Try.)

    The Zip extraction routine was trying to create a folder that already exists. But instead of causing an error or returning to frmMain, it ran back to the (disabled) startup form. Very odd.

    Thx.



    Saturday, May 18, 2019 1:38 AM