472,368 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

System.Timers.Timer -- new to programming, need help

Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a
System.Timers.Timer to work for me to display a splash screen for about two
seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
' Show the splash screen
MySplash.Show()
' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e
As System.Timers.ElapsedEventArgs)
' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module
Nov 20 '05 #1
10 2526
Hi,

In your sub main you show the splash screen and set up a timer.
Once it is done doing that the program ends because there is nothing else
for it to do. Place the timer in the splash screen and have it close it
self after 2 seconds. Try something like this.

Public Shared Sub Main()
' Show the splash screen
MySplash.TopMost = True
MySplash.Show()
Application.Run(frmMain)
End Sub
Ken

"WhiteSocksGuy" <wh***********@earthlink.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get
a
System.Timers.Timer to work for me to display a splash screen for about
two
seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
' Show the splash screen
MySplash.Show()
' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e
As System.Timers.ElapsedEventArgs)
' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module

Nov 20 '05 #2
Cor
Hi Kevin,

I prefer for a splash screen the windows.forms.timer it is for this easier
to handle.

Not that you should use it, but I have beneath a sample from a splash screen
inserted, it has more in it than absolute is necessary but it works nice.
(While it shows it does not stop your mainform program)

I hope this helps,

Cor
\\\form1
Private frm As New Form2
Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
timer1.Enabled = True
timer1.Interval = 12500
frm.Show()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
timer1.Enabled = False
frm.Close()
frm.Dispose()
End Sub

///
\\\form2

Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.CornflowerBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
Me.Opacity -= 0.01
If Me.Opacity = 0 Then
timer1.Enabled = False
Me.Close()
End If
End Sub
///
Module Module1

' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
' Show the splash screen
MySplash.Show()
' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module

Nov 20 '05 #3
* "Cor" <no*@non.com> scripsit:
I prefer for a splash screen the windows.forms.timer it is for this easier
to handle.
ACK.
Not that you should use it, but I have beneath a sample from a splash screen
inserted, it has more in it than absolute is necessary but it works nice.
(While it shows it does not stop your mainform program)


I would place the timer used for closing the splash screen on the
splash screen in order to avoid tight coupling.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!
Nov 20 '05 #4
Cor
>
I would place the timer used for closing the splash screen on the
splash screen in order to avoid tight coupling.


It did not close that way, maybe I should overlook it again but I think
there is still a reference.
There was someother one who had the same problem and than I thought why not
fix it with just an extra timer, (there are now on both forms a timer, but
maybe you have an idea?)

Cor

Nov 20 '05 #5
* "Cor" <no*@non.com> scripsit:
I would place the timer used for closing the splash screen on the
splash screen in order to avoid tight coupling.
It did not close that way, maybe I should overlook it again but I think
there is still a reference.


A reference to what? I am not really sure what you are referring to.
There was someother one who had the same problem and than I thought why not
fix it with just an extra timer,


Can you describe the problem in a few words or post a link?

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #6
Cor
Hi Kevin,

Correction, as me pointed on the timer on form1 is not needed.
(This was originaly not, so maybe I see the reason in future now, I deleted
it again in my sample).

Cor

\\\form1
Private frm As New Form2
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
frm.Show()
End Sub
///
\\\form2

Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.CornflowerBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
Me.Opacity -= 0.01
If Me.Opacity = 0 Then
timer1.Enabled = False
Me.Close()
End If
End Sub
///
Nov 20 '05 #7
Cor
Herfried,

I tested it in many ways, I cannot get the reason back why I added it, so it
should been something totally not important.

Thanks for pointing me on that.

Cor
Nov 20 '05 #8
Thanks for all your help, after much toying around with it I have finally
got the splash screen to operate how I want it to, and this is how I done it
for those who are also learning:

I have a splash screen, frmSplash and a main form, frmMain: (frmMain is the
startup object)
A timer component is on each form, interval set to 2.5 seconds for the
splash screen and 5 seconds for the main screen.

***************************************

code from Main Program window (frmMain):

Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As
System.EventArgs) _
Handles MyBase.Load
MyBase.Hide()
Dim mySplash As New frmSplash()
mySplash.ShowDialog()
End Sub

' timer interval set to 5 seconds
' after 5 seconds show the main form
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
MyBase.Show()
End Sub
End Class

code from Splash Screen (frmSplash):

Public Class frmSplash
' timer interval set to 2.5 seconds
' after 2.5 seconds the splash screen closes itself
Private Sub Timer2_Elapsed(ByVal sender As System.Object, _
ByVal e As
System.Timers.ElapsedEventArgs) _
Handles
Timer2.Elapsed
Me.Close()
End Sub
End Class

***************************************

Thanks again,

Kevin
"WhiteSocksGuy" <wh***********@earthlink.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
' Show the splash screen
MySplash.Show()
' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module

Nov 20 '05 #9
you can cause the thread its loading on to sleep also instead of a timer,
its a lot easier just put Thread.Sleep(200) in your app where you want it to
hold at
"WhiteSocksGuy" <wh***********@earthlink.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
' Show the splash screen
MySplash.Show()
' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module

Nov 20 '05 #10
* "Cor" <no*@non.com> scripsit:
I tested it in many ways, I cannot get the reason back why I added it, so it
should been something totally not important.


Thanks for playing around with that and sharing your experiences with
the group.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
3
by: Steve Lowe | last post by:
Hi, I'm getting into VB.net with the help of a few books, but have got a problem grasping how to implement a system.timers.timer Only 1 of my 3 books mentions timers and that's a...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
1
by: =?Utf-8?B?QnNtZW5nZW4=?= | last post by:
I create the timer like this: StreamingTimer = new System.Timers.Timer(); StreamingTimer.Elapsed += new System.Timers.ElapsedEventHandler(StreamingProc); StreamingTimer.Interval = 1000;...
2
by: BobAtVandy | last post by:
I'll greatly appreciate any help on this. Actually 2 questions: 1. I believe I need to use the Windows timer System.Timers.Timer . The examples I find on the web all access that timer by...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.