473,804 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subroutine with timer requirement

I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event
then checking the state of the counter in the subprocedure. But this doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark
Nov 21 '05 #1
13 1502
Hi,

Try something like this.

timer1.enabled = true
more stuff
end sub

timer1 tick event handler
progress = progress +.01
textbox1.text=p rogress.tostrin g
timer1.enabled = progress<1
end
Ken
------------------------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event
then checking the state of the counter in the subprocedure. But this doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark
Nov 21 '05 #2
Can you not just use a While loop with the DateTime.Now to wait a certain
number of seconds?

"mark" wrote:
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event
then checking the state of the counter in the subprocedure. But this doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #3
Try this Mark...
Sub mysub
stuff
'Wait one second
System.Threadin g.Thread.Sleep( 1000)
more stuff
end sub
"mark" wrote:
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event
then checking the state of the counter in the subprocedure. But this doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #4
I've done this several times. The best way to do it is use
System.Threadin g.Thread.Curren tThread.Sleep(< Number of miliseconds to
sleep>)

for example System.Threadin g.Thread.Curren tThread.Sleep(2 000) will sleep for
two seconds.

This works for both single process apps as well as multi-threaded apps.

John
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event then checking the state of the counter in the subprocedure. But this doesn't work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #5
<<Can you not just use a While loop with the DateTime.Now to wait a certain
number of seconds? >>

This would just kill CPU performance. Best way is using
system.threadin g.thread.sleep( )

John

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:31******** *************** ***********@mic rosoft.com...
Can you not just use a While loop with the DateTime.Now to wait a certain
number of seconds?

"mark" wrote:
I have a sub which needs to do some things then wait a specified length of time before going on. I tried adding a timer with counter in its tick event then checking the state of the counter in the subprocedure. But this doesn't work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #6

Ken:

It still hangs up in the while loop. When I break the debugger progress=0.0?
"Ken Tucker [MVP]" wrote:
Hi,

Try something like this.

timer1.enabled = true
more stuff
end sub

timer1 tick event handler
progress = progress +.01
textbox1.text=p rogress.tostrin g
timer1.enabled = progress<1
end
Ken
------------------------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick event
then checking the state of the counter in the subprocedure. But this doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #7
Hi,

Get rid of the while loop let the timer tick event handle it.

Ken
---------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:45******** *************** ***********@mic rosoft.com...

Ken:

It still hangs up in the while loop. When I break the debugger progress=0.0?
"Ken Tucker [MVP]" wrote:
Hi,

Try something like this.

timer1.enabled = true
more stuff
end sub

timer1 tick event handler
progress = progress +.01
textbox1.text=p rogress.tostrin g
timer1.enabled = progress<1
end
Ken
------------------------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick
event
then checking the state of the counter in the subprocedure. But this
doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark

Nov 21 '05 #8
You are correct and i'm sure the thread.sleep is the best way to go. I'm
used to VB3 programming and didn't have the thread class. I used the Now
function a lot in a restaurant cash register program that we used in our
restaurant and along with DoEvents, the CPU was able to keep up with
continuous ringing up of tickets and storing them in a database...fast er than
the waitress could enter the tickets from two cash registers. Still learning
VB.Net though.

"John Armenia" wrote:
<<Can you not just use a While loop with the DateTime.Now to wait a certain
number of seconds? >>

This would just kill CPU performance. Best way is using
system.threadin g.thread.sleep( )

John

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:31******** *************** ***********@mic rosoft.com...
Can you not just use a While loop with the DateTime.Now to wait a certain
number of seconds?

"mark" wrote:
I have a sub which needs to do some things then wait a specified length of time before going on. I tried adding a timer with counter in its tick event then checking the state of the counter in the subprocedure. But this doesn't work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark


Nov 21 '05 #9
Ken,
That fixes the program hang-up. But the delay does not occur.

"Ken Tucker [MVP]" wrote:
Hi,

Get rid of the while loop let the timer tick event handle it.

Ken
---------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:45******** *************** ***********@mic rosoft.com...

Ken:

It still hangs up in the while loop. When I break the debugger progress=0.0?
"Ken Tucker [MVP]" wrote:
Hi,

Try something like this.

timer1.enabled = true
more stuff
end sub

timer1 tick event handler
progress = progress +.01
textbox1.text=p rogress.tostrin g
timer1.enabled = progress<1
end
Ken
------------------------
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a sub which needs to do some things then wait a specified length of
time before going on. I tried adding a timer with counter in its tick
event
then checking the state of the counter in the subprocedure. But this
doesn't
work:

dim progress as single

Sub mysub
stuff

timer1.enabled = true
while progress <1
textbox1.text=p rogress
end while

more stuff
end sub

timer1 tick event handler
progress = progress +.01
end

The textbox shows me that nothing is happening. The program hangs up.

What's the right way to do this? Should this be a threading application?


--
mark


Nov 21 '05 #10

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

Similar topics

5
7395
by: Stephan Wörmke | last post by:
Hi! In one of our experiments we are using piezo electric transducers to move a stage. So far a feedback loop was implemented using the real-time system from venturcom. We now would like to use timers instead. Is there any good way to implement timers with an accuracy and resolution of 1ms or better? Our software runs on windows and is written with Visual Studio 2003 .NET
2
1550
by: asadikhan | last post by:
Hi, I have a timer in javascript on my ASP.NET page. When the time expires (a point in my javascript code) I want to call a subroutine in my ASP.NET page. But I can't seem to figure out how to do this. My subroutine is actually a function I call as a result of a button click. But if the user doesn't click the button in the allotted time, I want to go ahead and call the function anyways. Any idea how I can do this?
3
1223
by: vipul DotNet | last post by:
hi friend, I have a function which can accept 2 parameters , one as any double value second as "Y" or "N" public sub abc(byval dblvalue as double,byval strvalue as string) end sub I want the subroutine to accept only "Y" or "N" as parameter else should
20
2423
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone line 1 and Thread B handles call activity on telephone line 2. They use a common SQL datasource, but all DataSets are unique to each thread. Is there a way for thread A to occasionally communication to thread B that something has happened? ...
2
1008
by: Jordan | last post by:
Is there a way I can analyze my VB.NET program to time each subroutine? I would like to see which routines take the longest. Thanks, jordan
1
382
by: BobAchgill | last post by:
Is there a way to kill or stop a timer once it is started? Or is there another better way to preempt a timed process before it times out? I have tried these combinations but timer1 just keeps on ticking till the scheduled Tick mark. 1) timer1.stop
3
1978
by: Kris Palmer | last post by:
hi, can somebody explain this problem? it's driving me crazy! i have a requirement to dynamically create a variable quantity of timers with associated start button based on the contents of a database. if i create system timers dynamically, i cannot reference them from the start button click event handler. the build error is ' <timer name> not declared> ---- however, if i declare the system timers outside runtime code, everything works...
1
1219
by: AVL | last post by:
Hi, I'm developing an online fun game called tambola... The requirement is as follows Each logged user will have a ticket generated for him.. The system should display the numbers from 1 to 99 after every 10 secs.... Presently, I've used a timer control to display the numbers after every 10 secs... The problem with the timer control is that, it's causing a postback after every 10 secs,,, which is a hit on the server..
4
5123
by: gaddamreddy | last post by:
Hai to all frns, Reqirement 1: 1.I need to send a Request to one server through UDP socket.at that time i have to start a timer (setted to 2 sec) if i wont get the Response/ACK from that corresponding ACK from that server within 2 sec.i need to send the Request again. for this i did like this. #include <sys/types.h> #include <sys/socket.h>
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9571
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
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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
10302
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,...
1
7608
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
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
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
3
2976
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.