Home

Awesome

UPDATE - This library has has moved to the Shiny Framework at https://github.com/shinyorg/shiny

ACR Background Jobs Plugin for Xamarin & Windows

Change Log - March 5, 2019

SUPPORT THIS PROJECT

Plugin.Jobs|NuGet

BUILDS

BranchStatus
MasterBuild status
DevBuild status

PLATFORMS

PlatformVersion
Android5.0+
iOS8+
Windows UWP16299+
Any Other PlatformMust Support .NET Standard 2.0

iOS, Android, & UWP implementations use Xamarin Essentials

FEATURES

DOCS

SETUP

Install From NuGet

Follow the Setup Guids

HOW TO USE

<a name="adhoc"></a>Creating a One-Time Adhoc Job


// To issue an adhoc task that can continue to run in the background 
CrossJobs.Current.RunTask(async () => 
{
    // your code
});

<a name="schedule"></a>Scheduling a background job

// first define your job
public class YourJob : IJob
{
    public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
    {
        var loops = jobInfo.GetValue("LoopCount", 25);

        for (var i = 0; i < loops; i++)
        {
            if (cancelToken.IsCancellationRequested)
                break;

            await Task.Delay(1000, cancelToken).ConfigureAwait(false);
        }
    }
}
var job = new JobInfo
{
    Name = "YourJobName",
    Type = typeof(YourJob),

    // these are criteria that must be met in order for your job to run
    BatteryNotLow = this.BatteryNotLow,
    DeviceCharging = this.DeviceCharging
    NetworkType = NetworkType.Any,
    Repeat = true; //defaults to true, set to false to run once OR set it inside a job to cancel further execution
};

// you can pass variables to your job
job.SetValue("LoopCount", 10);


// lastly, schedule it to go - don't worry about scheduling something more than once, we just update if your job name matches an existing one
CrossJobs.Current.Schedule(job);

<a name="cancel"></a>Cancelling Jobs

// Cancelling A Job
CrossJobs.Current.Cancel("YourJobName");

// Cancelling All Jobs
CrossJobs.Current.CancelAll();

<a name="ondemand"></a>Running Jobs On-Demand

// Run All Jobs On-Demand
var results = await CrossJobs.Current.RunAll();

// Run A Specific Job On-Demand
var result = await CrossJobs.Current.Run("YourJobName");