473,382 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

timer control

hi all,

i m having some problem in timer control.

sub timer.tick()
timer.stop()
do...something
timer.enabled = true
end sub

this works fine. but after timer.stop() when i try to enable it from some
other functions it doesnt work. and the timer stops forever

thnx
Jul 5 '06 #1
17 1849
Hello Ratnesh,
sub timer.tick()
timer.stop()
do...something
timer.enabled = true
end sub
After calling timer.Stop(), you need to call timer.Start() to restart the
timer.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 5 '06 #2
thanks jared,

but that not working either. i've tried both ways, even both together. but
no luck

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>sub timer.tick()
timer.stop()
do...something
timer.enabled = true
end sub

After calling timer.Stop(), you need to call timer.Start() to restart the
timer.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #3
Hello Ratnesh,
thanks jared,

but that not working either. i've tried both ways, even both together.
but no luck
What happens when you call Start( exception, or just nothing). Try toggling
the Enabled and not calling Stop() at all.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 5 '06 #4

when i call start or enabled=true. nothing happens in any case. but the tick
event doesnt fire after the interval.
i've also tried to toggle the enabled property and didnt use Stop()

still no luck. i dont know whats wrong.
its like this

sub timer.tick()
timer.stop() [or timer.enabled=false]
do...something
enabletimersub()
end sub
sub enabletimersub()
timer.enabled = true [or timer.start()]
end sub

thnx

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>thanks jared,

but that not working either. i've tried both ways, even both together.
but no luck

What happens when you call Start( exception, or just nothing). Try
toggling the Enabled and not calling Stop() at all.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #5
Hello Ratnesh,
when i call start or enabled=true. nothing happens in any case. but
the tick
event doesnt fire after the interval.
i've also tried to toggle the enabled property and didnt use Stop()
still no luck. i dont know whats wrong.
its like this
sub timer.tick()
timer.stop() [or timer.enabled=false]
do...something
enabletimersub()
end sub
sub enabletimersub()
timer.enabled = true [or timer.start()]
end sub
Can you post a code snippet that reproduces the issue?

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 5 '06 #6
its a huge code. but i think i found the reason. herez the deal

can this be a problem?
the do..something part runs on another thread which eventually calls the
enabletimersub()
so the main timer.tick() thread and enabletimersub() are on different
threads. is there any solution for this

sub timer.tick()
timer.stop() [or timer.enabled=false]
do...something
end sub
sub enabletimersub()
timer.enabled = true [or timer.start()]
end sub

sorry for the delay in telling this point
"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>when i call start or enabled=true. nothing happens in any case. but
the tick
event doesnt fire after the interval.
i've also tried to toggle the enabled property and didnt use Stop()
still no luck. i dont know whats wrong.
its like this
sub timer.tick()
timer.stop() [or timer.enabled=false]
do...something
enabletimersub()
end sub
sub enabletimersub()
timer.enabled = true [or timer.start()]
end sub

Can you post a code snippet that reproduces the issue?

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #7
here is the snippet

Private Sub enabletimersub()
MsgBox("hi")
tmr.Enabled = True
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles tmr.Tick
tmr.Stop()
Dim thread1 As New System.Threading.Thread(AddressOf msgboxfun)
thread1.Start()
End Sub
"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>when i call start or enabled=true. nothing happens in any case. but
the tick
event doesnt fire after the interval.
i've also tried to toggle the enabled property and didnt use Stop()
still no luck. i dont know whats wrong.
its like this
sub timer.tick()
timer.stop() [or timer.enabled=false]
do...something
enabletimersub()
end sub
sub enabletimersub()
timer.enabled = true [or timer.start()]
end sub

Can you post a code snippet that reproduces the issue?

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #8
Hello Ratnesh,
its a huge code. but i think i found the reason. herez the deal

can this be a problem?
the do..something part runs on another thread which eventually calls
the
enabletimersub()
so the main timer.tick() thread and enabletimersub() are on different
threads. is there any solution for this
That definately could be causing the behavior you are seeing.

The solution to this is to use Control.Invoke() to set Enabled on the thread
the timer lives on.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 5 '06 #9
thanks jared,
i found that too. but i m not sure how to use it. cna u show me in the
snippet or give me any weblink for the help??
Private Sub enabletimersub()
MsgBox("hi")
tmr.Enabled = True
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles tmr.Tick
tmr.Stop()
Dim thread1 As New System.Threading.Thread(AddressOf enabletimersub)
thread1.Start()
End Sub
"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>its a huge code. but i think i found the reason. herez the deal

can this be a problem?
the do..something part runs on another thread which eventually calls
the
enabletimersub()
so the main timer.tick() thread and enabletimersub() are on different
threads. is there any solution for this

That definately could be causing the behavior you are seeing.
The solution to this is to use Control.Invoke() to set Enabled on the
thread the timer lives on.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #10
Hello Ratnesh,
thanks jared,
i found that too. but i m not sure how to use it. cna u show me in the
snippet or give me any weblink for the help??
Private Sub enabletimersub()
MsgBox("hi")
tmr.Enabled = True
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles tmr.Tick
tmr.Stop()
Dim thread1 As New System.Threading.Thread(AddressOf
enabletimersub)
thread1.Start()
End Sub
Assuming that Me is a Form or Control of some kind, try the following

Sub enableTimerSub()
Me.Invoke(CType(AddressOf enableTimerSubImpl, EventHandler))
End Sub

Sub enableTimerSubImpl(ByVal object As Sender, ByVal e As EventArgs)
tmr.Enabled = True
End Sub

Now you shoudl be able to call enableTimerSub() from the wrong thread and
it will invoke and call enableTimerSubImpl on the correct thread.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 5 '06 #11
thanks again and again
it works (finally)
phew!!

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>thanks jared,
i found that too. but i m not sure how to use it. cna u show me in the
snippet or give me any weblink for the help??
Private Sub enabletimersub()
MsgBox("hi")
tmr.Enabled = True
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles tmr.Tick
tmr.Stop()
Dim thread1 As New System.Threading.Thread(AddressOf
enabletimersub)
thread1.Start()
End Sub

Assuming that Me is a Form or Control of some kind, try the following

Sub enableTimerSub()
Me.Invoke(CType(AddressOf enableTimerSubImpl, EventHandler))
End Sub

Sub enableTimerSubImpl(ByVal object As Sender, ByVal e As EventArgs)
tmr.Enabled = True
End Sub

Now you shoudl be able to call enableTimerSub() from the wrong thread and
it will invoke and call enableTimerSubImpl on the correct thread.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 5 '06 #12
is it possible to do the same thing , If the timer control is in like class
module and not on any form.

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>thanks jared,
i found that too. but i m not sure how to use it. cna u show me in the
snippet or give me any weblink for the help??
Private Sub enabletimersub()
MsgBox("hi")
tmr.Enabled = True
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles tmr.Tick
tmr.Stop()
Dim thread1 As New System.Threading.Thread(AddressOf
enabletimersub)
thread1.Start()
End Sub

Assuming that Me is a Form or Control of some kind, try the following

Sub enableTimerSub()
Me.Invoke(CType(AddressOf enableTimerSubImpl, EventHandler))
End Sub

Sub enableTimerSubImpl(ByVal object As Sender, ByVal e As EventArgs)
tmr.Enabled = True
End Sub

Now you shoudl be able to call enableTimerSub() from the wrong thread and
it will invoke and call enableTimerSubImpl on the correct thread.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 6 '06 #13
Hello Ratnesh,
is it possible to do the same thing , If the timer control is in like
class module and not on any form.
You'll need a reference to a control on the foreground thread. Then you
can use thatControl.Invoke() to get onto the correct thread and reset the
timer.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 6 '06 #14
can you explain how?
bcoz the control doesnt seem to have the .invoke() method.

i m running timer in the Main module. which calls another class as a
saperate thread.

thnx

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>is it possible to do the same thing , If the timer control is in like
class module and not on any form.

You'll need a reference to a control on the foreground thread. Then you
can use thatControl.Invoke() to get onto the correct thread and reset the
timer.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 6 '06 #15
Hello Ratnesh,
can you explain how?
bcoz the control doesnt seem to have the .invoke() method.
i m running timer in the Main module. which calls another class as a
saperate thread.
Is control an instance of System.Windows.Forms.Conrol? If so it should have
an Invoke method.

http://msdn2.microsoft.com/en-us/library/zyzhdc6b.aspx

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 6 '06 #16
jared,

i have the normal windows.forms.timer control.

i've Main module with SubMain and this timer and few other things like
contextmenu, trayicon etc
now on timer.tick i m calling another class function on seperate thread. on
end of that thread i want to start timer again.

the problem is, if it was a form i could've called the invoke method simply.
but here i dont know how to implement this.
this is tray application, so it only stays in tray.

thnx

"Jared Parsons [MSFT]" <ja******@online.microsoft.comwrote in message
news:61************************@msnews.microsoft.c om...
Hello Ratnesh,
>can you explain how?
bcoz the control doesnt seem to have the .invoke() method.
i m running timer in the Main module. which calls another class as a
saperate thread.

Is control an instance of System.Windows.Forms.Conrol? If so it should
have an Invoke method.

http://msdn2.microsoft.com/en-us/library/zyzhdc6b.aspx

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.


Jul 6 '06 #17
Hello Ratnesh,
jared,

i have the normal windows.forms.timer control.

i've Main module with SubMain and this timer and few other things like
contextmenu, trayicon etc
now on timer.tick i m calling another class function on seperate
thread. on
end of that thread i want to start timer again.
the problem is, if it was a form i could've called the invoke method
simply.
but here i dont know how to implement this.
this is tray application, so it only stays in tray.
Add a shared field to your module of type System.Windows.Forms.Control.
On the main thread (the one where you originally created the timers), addd
the following lines

mySharedControl = New Control()
mySharedControl.CreateControl()

Since mySharedControl is a shared field you can access it from your background
method and use it to invoke back into the foreground thread.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jul 6 '06 #18

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

Similar topics

4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
11
by: Steve Jorgensen | last post by:
I've recently been playing with some UI ideas that require the user of a timer to drive animation. The problem I'm having is that Access routinely stops firing timer events for long periods of...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
2
by: vinay | last post by:
Hi I must be missing some obvious point, but can someone let me know how do I add a windows.forms.timer control to a form at run time Private TM as new windows.forms.time Dim sForm as for ...
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...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.