473,385 Members | 1,325 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,385 software developers and data experts.

System.Timer!

Hi All, I have a Win Svc (.net) running on my server. At midnight I need to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every 30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA
Jan 18 '07 #1
11 2349
Don't use a windows service. Instead, switch it to a console or
windows application, and setup a Scheduled task.

Vai2000 wrote:
Hi All, I have a Win Svc (.net) running on my server. At midnight I need to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every 30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA
Jan 18 '07 #2
Can't do console, has to be a svc since its polling on a dir

"Andy" <an***@med-associates.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
Don't use a windows service. Instead, switch it to a console or
windows application, and setup a Scheduled task.

Vai2000 wrote:
Hi All, I have a Win Svc (.net) running on my server. At midnight I need
to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every
30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA

Jan 18 '07 #3
Vai2000,

I would to this. I would set up first a small timer (meaning a small
interval) and then at this timer activation, I would check the datetime.now
and by then set up another time with a bigger interval that would reach the
desired time you want. Using this approach, even that the service is stopped
and then re-started again, it would correct the timer to fire at the right
time.
--
Regards,
Robson Siqueira
Enterprise Architect
"Vai2000" <no****@microsoft.comwrote in message
news:eq**************@TK2MSFTNGP04.phx.gbl...
Hi All, I have a Win Svc (.net) running on my server. At midnight I need
to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every
30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA


Jan 18 '07 #4
"Vai2000" <no****@microsoft.comwrote in message
news:eq**************@TK2MSFTNGP04.phx.gbl...
Hi All, I have a Win Svc (.net) running on my server. At midnight I need to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every 30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA

One option is to use WMI and System.Management.
Here is a small console sample...

using System;
using System.Management;
class Program {
public static void Main() {
// Bind to local machine
WqlEventQuery q = new WqlEventQuery();
q.EventClassName = "__InstanceModificationEvent ";
// fire event at 0h0m0s
q.Condition = @"TargetInstance ISA 'Win32_LocalTime' AND TargetInstance.Hour = 0 AND
TargetInstance.Minute = 0 AND TargetInstance.Second = 0";
Console.WriteLine(q.QueryString);
using (ManagementEventWatcher w = new ManagementEventWatcher(q))
{
w.EventArrived += new EventArrivedEventHandler(TimeEventArrived);
w.Start();
Console.ReadLine(); // Block this thread for test purposes only....
w.Stop();
}
}
static void TimeEventArrived(object sender, EventArrivedEventArgs e) {
Console.WriteLine("This is your wake-up call");
Console.WriteLine("{0}", new
DateTime((long)(ulong)e.NewEvent.Properties["TIME_CREATED"].Value));
}
}

Note that the TimeEventArrived will run on a threadpool thread. Your service should
initialize this at the start, your OnStop should call ManagementEventWatcher .Stop.
Willy.

Jan 18 '07 #5
Great, will take WMI Solution!, thanks ya all

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:OR*************@TK2MSFTNGP03.phx.gbl...
"Vai2000" <no****@microsoft.comwrote in message
news:eq**************@TK2MSFTNGP04.phx.gbl...
Hi All, I have a Win Svc (.net) running on my server. At midnight I need
to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every
30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA

One option is to use WMI and System.Management.
Here is a small console sample...

using System;
using System.Management;
class Program {
public static void Main() {
// Bind to local machine
WqlEventQuery q = new WqlEventQuery();
q.EventClassName = "__InstanceModificationEvent ";
// fire event at 0h0m0s
q.Condition = @"TargetInstance ISA 'Win32_LocalTime' AND
TargetInstance.Hour = 0 AND
TargetInstance.Minute = 0 AND TargetInstance.Second = 0";
Console.WriteLine(q.QueryString);
using (ManagementEventWatcher w = new ManagementEventWatcher(q))
{
w.EventArrived += new EventArrivedEventHandler(TimeEventArrived);
w.Start();
Console.ReadLine(); // Block this thread for test purposes only....
w.Stop();
}
}
static void TimeEventArrived(object sender, EventArrivedEventArgs e) {
Console.WriteLine("This is your wake-up call");
Console.WriteLine("{0}", new
DateTime((long)(ulong)e.NewEvent.Properties["TIME_CREATED"].Value));
}
}

Note that the TimeEventArrived will run on a threadpool thread. Your
service should
initialize this at the start, your OnStop should call
ManagementEventWatcher .Stop.
>

Willy.

Jan 18 '07 #6
Vai2000 escribió:
Great, will take WMI Solution!, thanks ya all
But take in account that WMI is not portable.

Regards,

Andrés [ knocte ]

--
Jan 18 '07 #7
""Andrés G. Aragoneses [ knocte ]"" <kn****@NO-SPAM-PLEASE-gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Vai2000 escribió:
>Great, will take WMI Solution!, thanks ya all

But take in account that WMI is not portable.
?? Who's talking about portability here? The OP is talking about .NET Framework based
Windows Services, are these considered portable?

Willy.

Jan 18 '07 #8
Willy Denoyette [MVP] escribió:
""Andrés G. Aragoneses [ knocte ]"" <kn****@NO-SPAM-PLEASE-gmail.com>
wrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
>Vai2000 escribió:
>>Great, will take WMI Solution!, thanks ya all

But take in account that WMI is not portable.

?? Who's talking about portability here? The OP is talking about .NET
Framework based Windows Services, are these considered portable?
Yep, you can launch windows services with Mono.

Regards,

Andrés [ knocte ]

--
Jan 18 '07 #9
See this post:
http://groups.google.com/group/micro...7ecfd06fa63c7f

You can "code up" a timer. and do a little math to figure out how to get it
pop at an exact time.
See
http://msdn2.microsoft.com/en-us/lib...rcallback.aspx
"Vai2000" <no****@microsoft.comwrote in message
news:eq**************@TK2MSFTNGP04.phx.gbl...
Hi All, I have a Win Svc (.net) running on my server. At midnight I need
to
do some manipulations....how can I invoke a timer at midnight?
Right now I have plugged in the ElapsedEvent which is being called every
30
seconds inside it I check for datetime whether its midnight or not...

Kindly throw some smart suggestions!!!
TIA


Jan 18 '07 #10
""Andrés G. Aragoneses [ knocte ]"" <kn****@NO-SPAM-PLEASE-gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Willy Denoyette [MVP] escribió:
>""Andrés G. Aragoneses [ knocte ]"" <kn****@NO-SPAM-PLEASE-gmail.com>
wrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
>>Vai2000 escribió:
Great, will take WMI Solution!, thanks ya all

But take in account that WMI is not portable.

?? Who's talking about portability here? The OP is talking about .NET
Framework based Windows Services, are these considered portable?

Yep, you can launch windows services with Mono.

Regards,

Andrés [ knocte ]

--
Yep, albeit not documented yet (just like a bunch of other stuff), Anyway, who asked about
mono?
Even when "Services" are in the mono distro what makes you wonder that the Services YOU
implement on windows are/should be portable? Services are always for specialized/dedicated
tasks. This is not about portability, this is about availability. All depends on what your
service's task looks like. Say that I'm accessing an SQL Server Analysis Server or BizTalk,
or simply,that I'm using V3's WCF from a service, should I stay away from it because - not
available - on other platforms?

Willy.

Jan 19 '07 #11
Willy Denoyette [MVP] escribió:
>>>>Great, will take WMI Solution!, thanks ya all

But take in account that WMI is not portable.
?? Who's talking about portability here? The OP is talking about .NET
Framework based Windows Services, are these considered portable?

Yep, you can launch windows services with Mono.
Yep, albeit not documented yet (just like a bunch of other stuff),
Not documented in Microsoft documentation, but...

Anyway, who asked about mono?
Nobody. But I thought that for the 90% people of this list,
interoperability and portability are important. And now, the most
interesting platform that allows this with .NET is Mono.

Even when "Services" are in the mono distro what makes you wonder that
the Services YOU implement on windows are/should be portable? Services
are always for specialized/dedicated tasks. This is not about
portability, this is about availability. All depends on what your
service's task looks like. Say that I'm accessing an SQL Server Analysis
Server or BizTalk, or simply,that I'm using V3's WCF from a service,
should I stay away from it because - not available - on other platforms?
Well, that's your decision. In my case, my professional circumstances
require me to always look at portability. In the case we are discussing
now, it's just "Vai2000"'s decision. I only just wanted to point out
this to him.

Regards,

Andrés [ knocte ]

--
Jan 19 '07 #12

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

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
4
by: Bilo | last post by:
I have a Windows Forms Class MainGUI I have declared MainGUI maingui; public System.ComponentModel.Container components = new Container(); in the Class I call another class MediaDriver with...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
1
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: ...
4
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...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
5
by: Brian | last post by:
Hello all. I have a simple application that I was using to test and understand the System.Timers.Timer and noticed that when I stop the application, on occasion, it throughs the following...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.