TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

System.Timers.Timer

VB.NET

 
 
Thread Tools Display Modes
Unread 05-09-2007, 12:01 PM   #1
Guy Cohen
Guest
 
Posts: n/a
System.Timers.Timer

Hi all
I need a sample with timers.
I read the samples on the net with consol output but I want to change (for
example) a text box content on my form and this sample is not good for
that...
TIA
Guy


 
Unread 05-09-2007, 01:01 PM   #2
rowe_newsgroups
Guest
 
Posts: n/a
Re: System.Timers.Timer

On Sep 5, 8:12 am, "Guy Cohen" <noem...@please.com> wrote:
> Hi all
> I need a sample with timers.
> I read the samples on the net with consol output but I want to change (for
> example) a text box content on my form and this sample is not good for
> that...
> TIA
> Guy


For Windows forms you should (imo) use the System.Windows.Forms.Timer
object. Add the object to your form, set the interval property (in
milliseconds), and add an event handler to the timer's Tick event. In
that method you do any actions you want to occur when the timer
"ticks".

Let me know if you need further help.

Thanks,

Seth Rowe

 
Unread 05-09-2007, 02:01 PM   #3
Guy Cohen
Guest
 
Posts: n/a
Re: System.Timers.Timer

Hi
I know that but I really want to use system.timers.timer for practice
purposes
The final solution is a service not a form...
TIA
Guy
"rowe_newsgroups" <rowe_email***********> wrote in message
news:1188996733.621660.229170@d55g2000hsg.googlegr oups.com...
> On Sep 5, 8:12 am, "Guy Cohen" <noem...@please.com> wrote:
>> Hi all
>> I need a sample with timers.
>> I read the samples on the net with consol output but I want to change
>> (for
>> example) a text box content on my form and this sample is not good for
>> that...
>> TIA
>> Guy

>
> For Windows forms you should (imo) use the System.Windows.Forms.Timer
> object. Add the object to your form, set the interval property (in
> milliseconds), and add an event handler to the timer's Tick event. In
> that method you do any actions you want to occur when the timer
> "ticks".
>
> Let me know if you need further help.
>
> Thanks,
>
> Seth Rowe
>



 
Unread 05-09-2007, 02:01 PM   #4
rowe_newsgroups
Guest
 
Posts: n/a
Re: System.Timers.Timer

On Sep 5, 10:19 am, "Guy Cohen" <noem...@please.com> wrote:
> Hi
> I know that but I really want to use system.timers.timer for practice
> purposes
> The final solution is a service not a form...
> TIA
> Guy"rowe_newsgroups" <rowe_em...***********> wrote in message
>
> news:1188996733.621660.229170@d55g2000hsg.googlegr oups.com...
>
> > On Sep 5, 8:12 am, "Guy Cohen" <noem...@please.com> wrote:
> >> Hi all
> >> I need a sample with timers.
> >> I read the samples on the net with consol output but I want to change
> >> (for
> >> example) a text box content on my form and this sample is not good for
> >> that...
> >> TIA
> >> Guy

>
> > For Windows forms you should (imo) use the System.Windows.Forms.Timer
> > object. Add the object to your form, set the interval property (in
> > milliseconds), and add an event handler to the timer's Tick event. In
> > that method you do any actions you want to occur when the timer
> > "ticks".

>
> > Let me know if you need further help.

>
> > Thanks,

>
> > Seth Rowe


Okay - this will be a bit more complicated than I had hoped. The
System.Timers.Timer's Elapsed event is raised on a thread separate
from the UI so we have to delegate access back to the form in order to
change the textbox. Most likely these cross-thread operations could be
ignored in a service, depending on what you are doing.

Copy and paste the below code into a new window's form and run it -
you should see the textbox on the form be incremented with every tick.

///////////////////
Imports System.Timers

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim timer As New Timer(1000)
AddHandler timer.Elapsed, AddressOf timer_Elapsed
Dim textBox As New TextBox()
textBox.Name = "TextBox1"
Me.Controls.Add(textBox)
timer.Start()
End Sub

Public Delegate Sub IncrementTextBoxDelegate()

Public Sub IncrementTextBox()
Dim textBox As TextBox =
DirectCast(Me.Controls.Find("TextBox1", True)(0), TextBox)
Dim ticks As Integer
If Integer.TryParse(textBox.Text.Replace(" Ticks", ""), ticks)
Then
ticks += 1
textBox.Text = String.Format("{0} Ticks", ticks)
Else
textBox.Text = "0 Ticks"
End If
End Sub

Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As
ElapsedEventArgs)
If Me.InvokeRequired Then
Dim incrementTextBoxDelegate As New
IncrementTextBoxDelegate(AddressOf IncrementTextBox)
Me.BeginInvoke(incrementTextBoxDelegate)
Else
IncrementTextBox()
End If
End Sub

End Class
///////////////////

Thanks,

Seth Rowe

 
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link Timer to a new thread RP C#(C Sharp) 2 05-09-2007 09:00 AM
Timer to lock computer. Revelation1 Microsoft Office 4 28-08-2007 11:54 AM
Funny black timer looking icon John Desselle Microsoft Office 4 28-08-2007 08:43 AM
countdown timer kev Windows XP 2 27-08-2007 05:36 PM
Performance timer in C rajesh_b_2k Programming 9 20-02-2007 05:04 AM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 11:49 AM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional