473,785 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I make my program more efficient ?

Hi;

I have designed a vb.net program that reads a dateTime value from a database
table and then compares it to Now() through dateTime.compar e(). I have loaded
an array with my datetime values from my table and I loop through this until a
match is made and then I run another program. Since I am continously checking
the system for a specific time the CPU stays at 99 %. I tried adding a do
loop and a timer to try to slow down the time between iterations of my
comparison loop but I still don't have the time right.

Here is my code if it's helps:

Do
For y = 0 to Len(holdDateTim e_Start(y))
If dateTime.Compar e(holdDateTime_ start(y), Now) = 0 then
processJobs(hol dJobName(y))
end if
Exit For
next

initializeTimer ()

Do
Loop until Timer1.interval = 0

y = 0

Loop Until dateTIme.Compar e("08/31/2006 12:00:00 AM", Now) = 0
Yes, I am trying to build my on task sceduler since the windows version
doesn't fit my needs.

Thanks for your suggestions.
--
Gordon
Aug 11 '06 #1
8 1585
Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and only
get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What feature
are you looking for cause it's quite strong and polyvalent...

Aug 11 '06 #2
Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I happened
to notice
the daily trigger example which would meet some of my needs but I notice
that one of the requirements is Windows Vista. I work for a financial
institution and it will probably be a couple of years after the mainstream
uses Vista before we adopt it.

Is there support for dealing with the task scheduler already in VS 2003 ?

Thanks for your answer did you say to look at manipulating the TickFrequency
property ?
--
Gordon
"crazyone" wrote:
Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and only
get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What feature
are you looking for cause it's quite strong and polyvalent...

Aug 11 '06 #3
No i simply meant to use a control on a form such as a timer and set
the frequency in seconds... that would allow you to check the time each
second without having to rely on loop endlessly and checking millions
of times a second.

Aug 11 '06 #4
Hello gordon,
The Win2k and XP task schedulers both support daily events.

-Boo
Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I
happened
to notice
the daily trigger example which would meet some of my needs but I
notice
that one of the requirements is Windows Vista. I work for a financial
institution and it will probably be a couple of years after the
mainstream
uses Vista before we adopt it.
Is there support for dealing with the task scheduler already in VS
2003 ?

Thanks for your answer did you say to look at manipulating the
TickFrequency property ?

"crazyone" wrote:
>Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and
only get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What
feature are you looking for cause it's quite strong and polyvalent...

Aug 14 '06 #5
Hi

If you're simply trying to compare Now() with existing entries in the
DB then why not do the filtering in your DB call.

i.e. do a "Select * from mytable Where myTimeField = Now()" or
GetDate() if more appropriate. That way you don't have to loop through
all the records each time as you'll only get matching records returned.
If you're concerned about 'missing' any of the DB values due to time
lapses between your DB calls then add a "Between Now() and Now()+1
minute" or whatever.

Hope that helps
Martin
GhostInAK wrote:
Hello gordon,
The Win2k and XP task schedulers both support daily events.

-Boo
Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I
happened
to notice
the daily trigger example which would meet some of my needs but I
notice
that one of the requirements is Windows Vista. I work for a financial
institution and it will probably be a couple of years after the
mainstream
uses Vista before we adopt it.
Is there support for dealing with the task scheduler already in VS
2003 ?

Thanks for your answer did you say to look at manipulating the
TickFrequency property ?

"crazyone" wrote:
Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and
only get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What
feature are you looking for cause it's quite strong and polyvalent...
Aug 14 '06 #6
Here is a simple soultion to your problem. There's no error handling. It's
just a quick sample.

Public Class Form1
Dim value(3) As DateTime
Dim index As Integer = 0
Dim dt As TimeSpan
Dim Timer2 As New System.Timers.T imer()

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

value(0) = CDate("8/14/2006 11:12:47 AM")
value(1) = CDate("8/14/2006 11:13:27 AM")
value(2) = CDate("8/14/2006 11:13:33 AM")
value(3) = CDate("8/14/2006 11:13:59 AM")
dt = value(0) - Now

CreateTimer()

End Sub

Private Sub CreateTimer()

Timer2.Interval = dt.TotalMillise conds
Timer2.Enabled = True
AddHandler Timer2.Elapsed, _
New System.Timers.E lapsedEventHand ler(AddressOf
Me.Timer1_Elaps ed)
End Sub

Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers.E lapsedEventArgs )

index += 1
Debug.WriteLine ("Message " & index & ": " & Now)
If index < 4 Then
dt = value(index) - Now
Timer2.Interval = dt.TotalMillise conds
Else
Timer2.Enabled = False
Debug.WriteLine ("Disabled")
End If
End Sub
End Class
"Pritcham" <do************ ******@hotmail. comwrote in message
news:11******** **************@ 74g2000cwt.goog legroups.com...
Hi

If you're simply trying to compare Now() with existing entries in the
DB then why not do the filtering in your DB call.

i.e. do a "Select * from mytable Where myTimeField = Now()" or
GetDate() if more appropriate. That way you don't have to loop through
all the records each time as you'll only get matching records returned.
If you're concerned about 'missing' any of the DB values due to time
lapses between your DB calls then add a "Between Now() and Now()+1
minute" or whatever.

Hope that helps
Martin
GhostInAK wrote:
>Hello gordon,
The Win2k and XP task schedulers both support daily events.

-Boo
Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I
happened
to notice
the daily trigger example which would meet some of my needs but I
notice
that one of the requirements is Windows Vista. I work for a financial
institution and it will probably be a couple of years after the
mainstream
uses Vista before we adopt it.
Is there support for dealing with the task scheduler already in VS
2003 ?

Thanks for your answer did you say to look at manipulating the
TickFrequency property ?

"crazyone" wrote:

Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and
only get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What
feature are you looking for cause it's quite strong and polyvalent...

Aug 14 '06 #7
Hi ;

Thanks for all for your suggestions.

I also posted my question with the visual studio general newsgroup and I got
a very simple solution.

Place this statement just outside my next statement :

Threading.Threa d.Sleep(number of milliseconds to pause).

This works just as well as the windows.timer.

--
Gordon
"Mudhead" wrote:
Here is a simple soultion to your problem. There's no error handling. It's
just a quick sample.

Public Class Form1
Dim value(3) As DateTime
Dim index As Integer = 0
Dim dt As TimeSpan
Dim Timer2 As New System.Timers.T imer()

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

value(0) = CDate("8/14/2006 11:12:47 AM")
value(1) = CDate("8/14/2006 11:13:27 AM")
value(2) = CDate("8/14/2006 11:13:33 AM")
value(3) = CDate("8/14/2006 11:13:59 AM")
dt = value(0) - Now

CreateTimer()

End Sub

Private Sub CreateTimer()

Timer2.Interval = dt.TotalMillise conds
Timer2.Enabled = True
AddHandler Timer2.Elapsed, _
New System.Timers.E lapsedEventHand ler(AddressOf
Me.Timer1_Elaps ed)
End Sub

Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers.E lapsedEventArgs )

index += 1
Debug.WriteLine ("Message " & index & ": " & Now)
If index < 4 Then
dt = value(index) - Now
Timer2.Interval = dt.TotalMillise conds
Else
Timer2.Enabled = False
Debug.WriteLine ("Disabled")
End If
End Sub
End Class
"Pritcham" <do************ ******@hotmail. comwrote in message
news:11******** **************@ 74g2000cwt.goog legroups.com...
Hi

If you're simply trying to compare Now() with existing entries in the
DB then why not do the filtering in your DB call.

i.e. do a "Select * from mytable Where myTimeField = Now()" or
GetDate() if more appropriate. That way you don't have to loop through
all the records each time as you'll only get matching records returned.
If you're concerned about 'missing' any of the DB values due to time
lapses between your DB calls then add a "Between Now() and Now()+1
minute" or whatever.

Hope that helps
Martin
GhostInAK wrote:
Hello gordon,
The Win2k and XP task schedulers both support daily events.

-Boo

Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I
happened
to notice
the daily trigger example which would meet some of my needs but I
notice
that one of the requirements is Windows Vista. I work for a financial
institution and it will probably be a couple of years after the
mainstream
uses Vista before we adopt it.
Is there support for dealing with the task scheduler already in VS
2003 ?

Thanks for your answer did you say to look at manipulating the
TickFrequency property ?

"crazyone" wrote:

Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and
only get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What
feature are you looking for cause it's quite strong and polyvalent...


Aug 14 '06 #8
The difference between the two options are that the thread.sleep statement
forces the current thread to stop executing during the sleep. In many cases
this is fine. The timer solution instructs Windows to alert your program
after a specified interval that it can do something. The calling thread
doesn't stall, but you get the added complexity of a multi-threaded
application. Sometimes this is what you want.

Mike Ober.

"Gordon" <Go****@discuss ions.microsoft. comwrote in message
news:2B******** *************** ***********@mic rosoft.com...
Hi ;

Thanks for all for your suggestions.

I also posted my question with the visual studio general newsgroup and I
got
a very simple solution.

Place this statement just outside my next statement :

Threading.Threa d.Sleep(number of milliseconds to pause).

This works just as well as the windows.timer.

--
Gordon
"Mudhead" wrote:
>Here is a simple soultion to your problem. There's no error handling.
It's
just a quick sample.

Public Class Form1
Dim value(3) As DateTime
Dim index As Integer = 0
Dim dt As TimeSpan
Dim Timer2 As New System.Timers.T imer()

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click

value(0) = CDate("8/14/2006 11:12:47 AM")
value(1) = CDate("8/14/2006 11:13:27 AM")
value(2) = CDate("8/14/2006 11:13:33 AM")
value(3) = CDate("8/14/2006 11:13:59 AM")
dt = value(0) - Now

CreateTimer()

End Sub

Private Sub CreateTimer()

Timer2.Interval = dt.TotalMillise conds
Timer2.Enabled = True
AddHandler Timer2.Elapsed, _
New System.Timers.E lapsedEventHand ler(AddressOf
Me.Timer1_Elap sed)
End Sub

Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers. ElapsedEventArg s)

index += 1
Debug.WriteLine ("Message " & index & ": " & Now)
If index < 4 Then
dt = value(index) - Now
Timer2.Interval = dt.TotalMillise conds
Else
Timer2.Enabled = False
Debug.WriteLine ("Disabled")
End If
End Sub
End Class
"Pritcham" <do************ ******@hotmail. comwrote in message
news:11******* *************** @74g2000cwt.goo glegroups.com.. .
Hi

If you're simply trying to compare Now() with existing entries in the
DB then why not do the filtering in your DB call.

i.e. do a "Select * from mytable Where myTimeField = Now()" or
GetDate() if more appropriate. That way you don't have to loop through
all the records each time as you'll only get matching records returned.
If you're concerned about 'missing' any of the DB values due to time
lapses between your DB calls then add a "Between Now() and Now()+1
minute" or whatever.

Hope that helps
Martin
GhostInAK wrote:
Hello gordon,
The Win2k and XP task schedulers both support daily events.

-Boo

Why won't the task sceduler fit my needs ?

I did a little research into programming some of it's objects, I
happened
to notice
the daily trigger example which would meet some of my needs but I
notice
that one of the requirements is Windows Vista. I work for a
financial
institution and it will probably be a couple of years after the
mainstream
uses Vista before we adopt it.
Is there support for dealing with the task scheduler already in VS
2003 ?

Thanks for your answer did you say to look at manipulating the
TickFrequency property ?

"crazyone" wrote:

Simple suggestion, create a timer that responds to a certain TICK
frequency. That way, you let the computer manage the workload and
only get to run your code every X millisecond.

If a millisecond is not precise enough then i suggest searching for
another feature but i sincerely doubt that will be too long... With
a
timer set to 1 second interval, the processor will not loop at 99%
constantly at least.

Math

PS: What makes you think the task scheduler wouldn't work? What
feature are you looking for cause it's quite strong and
polyvalent.. .




Aug 15 '06 #9

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

Similar topics

3
2497
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can perform the task within "Write". 1-10 different threads may call "Write" simultaneously and continuously, some in a greedy manner. That is to say that some of the threads calling "Write" will take all they can get, while other threads may only call...
354
15927
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets hooked up to interfaces. The Gtk is more than enough gui.
10
2691
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
19
2446
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
0
1181
by: Frank Birbacher | last post by:
Hi! sphenxes@gmail.com schrieb: Why is the referenceNumber a string? Are there always *exactly* six alternatives? The alternatives could be a std::deque which can resize as needed.
3
2844
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
82
3739
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from. Let's name the update method as doUpdate and stl::map read methods as getData and copyData. Since stl::map is not thread-safe, we should do synchronization by ourselves. A usable solution is to create a boost::mutex::scoped_lock object in all above...
12
2014
by: Atropo | last post by:
Hi all. Having several strings how do i combine them to construct a command; lets say to run the date command. string str = "14/10/08 19:06:09"; strDD = str.substr(0,2); strMM = str.substr(3,2); strAA = str.substr(6,2); strhh = str.substr(9,2);
36
2567
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\ unsigned int a2;\
2
1794
by: APmore | last post by:
Hi all, After writing a program, how do you check whether your program is: CPU efficient memory efficient How can assembly language learning help in writing an efficient program?
0
9647
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
9491
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
10163
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...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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
5397
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...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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
2894
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.