473,834 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Timers.T imer -- new to programming, need help

Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a
System.Timers.T imer 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.T imer(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.AutoRese t = False
' Enable the timer
aTimer.Enabled = True
End Sub

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

End Class

End Module
Nov 20 '05 #1
10 2714
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.TopMos t = True
MySplash.Show()
Application.Run (frmMain)
End Sub
Ken

"WhiteSocks Guy" <wh***********@ earthlink.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get
a
System.Timers.T imer 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.T imer(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.AutoRese t = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(By Val source As Object, _
ByVal e
As System.Timers.E lapsedEventArgs )
' 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.t imer 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.T imer
Private Sub Form1_Load(ByVa l sender _
As Object, ByVal e As System.EventArg s) _
Handles MyBase.Load
timer1.Enabled = True
timer1.Interval = 12500
frm.Show()
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, _
ByVal e As System.EventArg s) Handles timer1.Tick
timer1.Enabled = False
frm.Close()
frm.Dispose()
End Sub

///
\\\form2

Private WithEvents timer1 As New Windows.Forms.T imer
Private Sub Form2_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.Cornflowe rBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, _
ByVal e As System.EventArg s) 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.T imer(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.AutoRese t = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(By Val source As Object, _
ByVal e As System.Timers.E lapsedEventArgs )
' 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.t imer 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(ByVa l sender _
As Object, ByVal e As System.EventArg s) _
Handles MyBase.Load
frm.Show()
End Sub
///
\\\form2

Private WithEvents timer1 As New Windows.Forms.T imer
Private Sub Form2_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.Cornflowe rBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, _
ByVal e As System.EventArg s) 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(By Val sender As System.Object, _
ByVal e As
System.EventArg s) _
Handles MyBase.Load
MyBase.Hide()
Dim mySplash As New frmSplash()
mySplash.ShowDi alog()
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.E lapsedEventArgs ) 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.E lapsedEventArgs ) _
Handles
Timer2.Elapsed
Me.Close()
End Sub
End Class

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

Thanks again,

Kevin
"WhiteSocks Guy" <wh***********@ earthlink.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.T imer 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.T imer(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.AutoRese t = False
' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(By Val source As Object, _
ByVal e As System.Timers.E lapsedEventArgs )
' 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(20 0) in your app where you want it to
hold at
"WhiteSocks Guy" <wh***********@ earthlink.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.phx.gbl...
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.T imer 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.T imer(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.AutoRese t = False
' Enable the timer
aTimer.Enabled = True
End Sub

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

End Class

End Module

Nov 20 '05 #10

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

Similar topics

9
7884
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 might need to carry out some back-end processing without pausing the individual users' Session while that process runs. E.g. I might provide the ability for a user to upload a text file of job
5
9893
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 regularly; like every 1.5 secs. or so. I only ran into one issue - the MyTimer_Elapsed event handler was not updating the screen correctly all the time, often leaving large chunks of the screen un-painted for several seconds. On a whim I decided to...
1
2118
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: static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); private void dg_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { System.Timers.Timer timer = new System.Timers.Timer();
4
11140
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 the default of True. The Elapsed event handler updates the dialog box with how long before it will close, acting as a timer itself. The dialog has a time to close property which is checked every time the Elapsed event fires. The problem I have...
7
6108
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 seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
3
8635
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 Windows.Form.Timer Basically I need to have a 30 second delay in some module code. To help me get the hang of it - (that should really be start to get
5
12258
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 event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
1
414
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; StreamingTimer.Enabled = true; StreamingTimer.Start(); To dispose of the timer, I did this:
2
2119
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 'import System' . (That's System with a capital S.) I have pywin32 installed and 'import System' doesn't find System so I gather it's not in that package. Where does one get the package with Windows' System class? 2. The reason I've been...
0
9651
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10516
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10556
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9339
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7762
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5800
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3987
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3085
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.