public void SetComplete() { // assume we call this even if canceled. IsComplete = true; if (!IsCancelled) { this.Progress.SetEnd(); // true end. } CacheT <JobTracker> .Set(Key, this, 5 * 60); // no need to hang around too long }
public static JobTracker CreateJobTracker(string typeName, int userId, long size, bool cancelable = false) { // We are starting some async job that we want to track the progress of. if (size <= 0) { return(null); // not allowed. } string cacheKey = MakeKey(typeName, userId); var job = CacheT <JobTracker> .Get(cacheKey); if (job == null) { job = new JobTracker { JobTypeName = typeName, UserId = userId, Progress = new Progress2(size) }; } else if (job.IsComplete) { // just re-use done job job.FailureMsg = null; job.IsComplete = false; job.SetStartSize(size); } else { return(null); // cant dupe the active job. } if (cancelable) { job.Cancellation = new CancellationTokenSource(); } CacheT <JobTracker> .Set(cacheKey, job, 24 * 60 * 60); // update time return(job); }