Search code examples
.netdelay

How to add delay before application loads in .net?


I am coding a program in vb.net but I am facing a trouble which I don't know how to fix.

I have 3 forms.

Form 1 = Loading   
Form 2 = Successfully loaded    
Form 3 = Main

So, when the program starts, it opens the loading form and it is waiting until the program is loaded. I want to add a delay of 10 seconds after the load before the success page shows.

So, I tried these methods:

System.Threading.Thread.Sleep(10000)

But it freezes the application and it doesn't work as intended, it shows the application before 10 seconds.

And I also tried with Timer, setting the interval to 10,000 but it doesn't seem to work, it displays the form instantly.

Any alternative solutions???

My code:

Public Class Loading

    Private Sub Loading_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Me.Hide()
        Success.Show()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Interval = 10000
        Timer1.Stop()
    End Sub
End Class

Solution

  • I think that the best way is to use a timer.

    1. Create a timer with an interval of 10000ms
    2. Show the message in the elapsed event
    3. Dispose the timer