Kindly throw some smart suggestions!!!
TIA
"Andy" <an...@med-associates.com> wrote in message
news:1169140759....@l53g2000cwa.googlegroups.com...
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" <nos...@microsoft.com> wrote in message
news:eqVYTQyO...@TK2MSFTNGP04.phx.gbl...
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.
"Willy Denoyette [MVP]" <willy.d...@telenet.be> wrote in message
news:ORLXE4y...@TK2MSFTNGP03.phx.gbl...
But take in account that WMI is not portable.
Regards,
Andrés [ knocte ]
--
?? Who's talking about portability here? The OP is talking about .NET Framework based
Windows Services, are these considered portable?
Willy.
Yep, you can launch windows services with Mono.
Regards,
Andrés [ knocte ]
--
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/library/system.threading.timercallback.aspx
"Vai2000" <nos...@microsoft.com> wrote in message
news:eqVYTQyO...@TK2MSFTNGP04.phx.gbl...
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.
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 ]
--