Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Run code from windows service at a particular time

Posted on 2011-02-25
6
417 Views
Last Modified: 2012-05-11
Hi All

Is it possible to run code from inside a windows service at a particular time of day. I'm getting the time to run from a config file, and want to check for a file in a folder at that time.

I think I can do it by running the routine and storing the time, then use a timer to elapse until the next due time, but it would be so much easier to ask it to run at said time.

I cant use the scheduler.

Andy
0
Comment
Question by:Andy Green
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34979000
You can write your own windows service using vb.net

Have a look here :http://www.codeguru.com/vb/gen/vb_system/services/article.php/c4825
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 34979059
Have a thread that is running for each minute or for each x time. This thread should call the function you have and have a check in your function if the time is the same as your configured time.
0
 
LVL 3

Author Comment

by:Andy Green
ID: 35004487
Still stuck with this, My searches suggest using Thread.sleep, but I cant find any suitable code examples.

Any more thoughts anyone.

Andy
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 500 total points
ID: 35007767
Yes you need to use that. Your code should be something like this.

In service OnStart() function

Call RunServiceThread()


Public Sub RunServiceThread()

Dim ServiceThread As New thread(Address Of TestFunc)
ServiceThread.Start()

End Sub

Public Sub TestFunc()

 Do While True
                Thread.CurrentThread.Sleep(1000 * 60 * 2)  ' runs for every 2 minutes

If your condition then
Call your function.
End If

Loop
End Sub
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 35007771
You need to handle errors for threading.
0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 35038305
Thanks

Andy
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get the selected ValueMember of Combobox 5 40
VB: Convert 2 dates to specific format 24 52
Winform Module - What is the ASP.Net equiv 2 28
location of a form 2 25
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question