Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

Run code from windows service at a particular time

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
Andy Green
Asked:
Andy Green
  • 3
  • 2
1 Solution
 
Paul JacksonSoftware EngineerCommented:
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
 
srikanthreddyn143Commented:
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
 
Andy GreenAuthor Commented:
Still stuck with this, My searches suggest using Thread.sleep, but I cant find any suitable code examples.

Any more thoughts anyone.

Andy
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
srikanthreddyn143Commented:
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
 
srikanthreddyn143Commented:
You need to handle errors for threading.
0
 
Andy GreenAuthor Commented:
Thanks

Andy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now