1

I'm having a hard time planning how to implement the architecture. The problem:

>  A user can save a number of profiles:
>     Name
>     URL
>     Time Interval

Name       | URL      |Time Interval
Sample1    |s.com     |5 mins
Sample2    |x.com     |2 mins
Sample3    |xxx.com   |7 mins

The main purpose of the app is to download images set by the user through time interval. The problem is how can we check every profile with different intervals like for example the user created 20 profiles which have different time intervals.

We're going to be using WPF and WCF on this one.

  • If the user can choose the interval with a particular granularity (e.g. any whole number of minutes), then you must run a task every minute and determine for each download job whether it needs to be run this time or not. For instance, a counter and the modulo operator can do the job. – Kilian Foth Jan 29 '16 at 8:50
  • So I will have a service that runs every minute to check what task needs to be executed? – Prince Jea Jan 29 '16 at 8:56
1

I recommend you look at quartz.net which will help you with the scheduling part of the app. I tried my own scheduling and came unstuck very quickly. You can then focus your efforts on the logic of the app itself.

0

The most simple solution is to have a loop that goes in granulity of 1 second and checks if there is some profile to update, by checking time of it's last update ( should be set in .update() method of profile ) and it's interval.

Example pseudocode:

while(shouldRun()) {
  var startTime = currentTimeMiliseconds();
  for( var u : Users ) {
    if( u.getLastUpdateTime() + u.getInterval() <= currentTimeMiliseconds() ) {
      u.update();
    }
  }

  var diff = currentTimeMiliseconds() - startTime;
  if(diff < 1000) {
    sleepMiliseconds(1000-diff);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.