Scheduled task with windows services and system.timer.timer - windows-services

i want implement a windows services scheduled task.
I already created windows service. In a service i have implemented a timer.The timer is initialized at class interval. The timers interval is set in the start method of service and also it is enabled in the start method of the service. After timers elapsed event is fire i have done some actions.
My problem is that, i am in a dilemma. Lets say the action i have done in Elapsed event, lets say take one hour and the timers interval is set to half an hour. so there are chances that even if the previous call to elapsed event has not ended new call to elapsed event will occur.
my question will there be any conflict or is it ok or shall i use threads.
please give some advice

You can stop the timer at the begining of your long running method, then start it again at the end:
Timer.Change(Timeout.Infinite, Timeout.Infinite)
// do long task ...
Timer.Change(dueTime,period)

Related

Timer management in network requests

I have a question about managing timers in Swift.
Currently I have a ViewController that takes care of calling a rest network service, every 30 seconds, through a Timer that I initialize inside ViewDidLoad with an and with the value repeats: true.
Up to now there are no problems, the functioning seems quite correct to me.
However, I would like to understand a timer feature.
Let's say I decide to decrease the time from 30 seconds to 1 second, in this case, what happens with the network requests? From what I understand the timer, being scheduled every 1 second, this makes 1 request every second, but as we all know, there could be a delay in the response from the backend.
In this case, are subsequent requests queued?
Is there any way to say, wait for the backend response and then execute the second request?

How to run a function at a specific time everyday using ios swift3 [duplicate]

I have read this answer and I do not believe it has what I am looking for but I a am beginner and I am happy to have someone point out the answer in this link : dispatch_after - GCD in swift?
My goal: set a function to run at 9 AM in the user's time zone (or system's time zone) every single day.
I've used GCD very briefly to delay a function as follows (it works perfectly fine):
var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(10 * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
let alert = UIAlertView()
alert.title = "Foo Alert"
alert.message = "foo."
alert.addButtonWithTitle("OK")
alert.show()
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
});
So I wanted to fire it daily as I've mentioned above but the first thing I am stuck on is swapping out DISPATCH_TIME_NOW for a time zone relevant value? Do I even need to consider time zones or will simply replacing DISPATCH_TIME_NOW with military 09:00 be sufficient?
Also, any advice on the overall goal, scheduling to fire function same time every day would be much appreciated.
I'm also not married to using GCD for this goal but it was the one I ran into the most doing searches.
In short, you cannot generally execute some arbitrary function at some arbitrary time unless the app is still running. The dispatch_after presumes that the app is still running at the scheduled time, which is not generally assured. The dispatch_after is great for "do something in x seconds", not "do something tomorrow at 9am".
Yes, dispatch_after can perform some task on some background thread, but that's very different concept from having the app run in the background (i.e., when the app, itself, is no longer in foreground). Please refer to App Programming Guide for iOS: Background Execution, which enumerates all of the various background mechanisms.
The key technologies for performing something when the app is not currently active include:
Using background fetch, you can opportunistically check for new data on the server (but not per your schedule, but rather at the discretion of the OS).
If your app is serving several very specific tasks (e.g. music app, VOIP, navigation app, etc.) you can register for background operation.
You can schedule a local notification to fire at particular time (though it is incumbent on the user to see the notification and tap on it in order for the app to run). For more information see the Local and Remote Notification Programming Guide.
You can register for push notifications and then your server could push a notification to clients at some time of your choosing (but that requires server-side development).
There are other background tasks that can be configured (e.g. continue network requests in background, request a few minutes to finish some finite length task even if the app is no longer active, etc.), but those seem unrelated to your question.
If you could clarify what you want the app to do at the scheduled time, we might be able to advise what is possible and what the alternatives are. But, in broad brush strokes, those are the basic options you have.
Importantly, you should use dispatch_walltime instead of dispatch_time. The difference: If you set a dispatch_time for "1000 seconds from now" it will run 1000 seconds from now (if your app is running). But dispatch_walltime will calculate which time that is on the user's clock, and will run when the user's clock reaches that time.
So if you set up dispatch_time for 9am tomorrow morning, and I set the clock on my device forwards by five minutes, then dispatch_time will run when my clock displays 9:05am. dispatch_walltime will run at 9:00am. (You'll have to experiment what happens if I change the clock from 8:55am to 9:05am because then running when the clock shows 9:00am is obviously impossible).

Quartz .NET - remove trigger if all future fire times in past

I've set up the quartz scheduler to ignore misfires and move on to the next fire time (using .WithMisfireHandlingInstructionNextWithRemainingCount() and .WithMisfireHandlingInstructionDoNothing()). This works fine but if there is no next fire time the trigger will just keep the old next fire time that has already misfired and wait for it to fire (it will never fire because it is in the past).
The way I'm testing this is pausing a trigger and waiting for the fire times to pass/misfire. The trigger's state is updated to COMPLETE only after resuming and remains in the database. I want the trigger to remove itself from the database (like it normally does when complete). I also want the trigger to complete without me having to resume the trigger but that's a bonus.
So the problem was I was setting the start time (using .StartAt() method) to the start time of the intervals I was using. For example, let's say it is currently 9am on June 23rd. If I had a trigger that runs daily starting at 3am then the start time of the daily interval is 3am. However, I was also setting the start time of the trigger to 3am, which is in the past. This ended up causing me many issues.

automatically tracking time through start / stop progress

I like to track time spent on JIRA issues when I click on Start Progress and then Stop Progress, or Resolve.
Is it possible to get JIRA to automatically allocate time to the task, like say:
14:20: Clicked on Start Progress
14:45: Clicked on Stop Progress > Logs 25 minutes to the task
15:30: Clicked on Start Progress
15:45: Clicked on Resolve > Logs 15 minutes to the task.
Is this possible?
Yes, it is possible.
You might want to have a look at Listeners:
"A Listener is a class that implements one of the Listener interfaces. It is then called whenever events occur in JIRA. Using those events, you can then perform any action you want."
In your case you could implement the issueStarted, issueStopped and issueResolved method.
On issueStarted you could somehow save the current timestamp (e.g. in an invisible customfield) and on issueStopped/issueResolved you could trigger the creation of a worklog-entry.
There is an app on the Atlassian Marketplace, Clockwork Automated Timesheets, that does exactly that.
It fully integrates with Jira's workflow so that the time logged corresponds to how much time an issue was In Progress or had any other active status.
If necessary, the timers can always be started or stopped manually by using Start/Stop buttons.
There are also reports available.
At the moment the app is free.
Cheers,
Jacek

What happens if a job is scheduled in the past?

I'm new to Quartz.Net and I'm wondering what happens if a job is scheduled in the past? Is an exception thrown? Is it run immediately? I'm wondering if I need to guard for this condition when I schedule jobs.
You will get an exception if the trigger you are adding would never fire. There is a distinction here to note: you can schedule start time to be in the past but there needs to be some future time for the trigger to fire. So having start time of NOW()-1d is fine if you have firing happening after the time you add the trigger (EndTimeUtc in the future AND schedule that permits futher fires from now).
So you should check that GetNextFireTimeUtc returns non-null value for trigger you are adding.

Resources