• Mobile
  • Extensions
  • Releases
  • GitHub
  • Blog
  • Sponsor
Show / Hide Table of Contents
  • Home
  • Quick Start
  • Setup
    • Dependency Injection
    • Startup
    • Static Instances
    • iOS
    • Android
  • Configuration Extensions
  • Jobs
    • Setup
    • Create a Job
    • Querying, Cancelling, and Adhoc
    • Frequently Asked Questions
  • Bluetooth LE Client
    • Setup
    • Scanning
    • Peripheral
    • Best Practices
    • Manged Scanning
    • Managed Peripheral
  • Bluetooth LE Hosting
    • Setup
    • GATT
    • Advertising
  • Geofencing
  • GPS
    • Setup
  • Motion Activity
  • Local Notifications
    • Getting Started
    • Channels
  • Push Notifications
    • Getting Started
    • Native
    • Azure Notification Hubs
    • Firebase Messaging
    • One Signal
  • Beacons
    • Ranging
    • Monitoring (Background)
  • HTTP Transfers
    • Getting Started
    • Advanced
  • Framework
    • Getting Started
    • ViewModel
  • Sensors
    • Getting Started
    • Accelerometer
    • Ambient Light
    • Barometer
    • Compass
    • Gyroscope
    • Humidity
    • Magnetometer
    • Pedometer
    • Proximity
    • Temperature

Creating a Job

Create your job

The first thing you'll want to do is create your job by implementing the Shiny.Jobs.IJob interface.

using Shiny.Jobs;

namespace YourNamespace;

// 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);
        }
    }
}

Next, we need to define our job run parameters by defining a JobInfo. The job info allows you to pass in a dictionary of parameters to use within your job.

var job = new JobInfo
{
    Name = "YourJobName",
    Type = typeof(YourJob),

    // these are criteria that must be met in order for your job to run
    BatteryNotLow = true,
    DeviceCharging = false,
    RunInForeground = true,
    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, we need to register our job. There are two ways to do this

Through the shiny startup process (recommended)

services.RegisterJob(yourJobInfo);

OR Dynamically in your code - in order to do this, you still have to register the job manager in your startup


services.UseJobs();

IJobManager manager; // inject

// 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
manager.RegisterJob(job);

Foreground Jobs

Foreground jobs aren't really anything special. When your app comes to the foreground, we simply start a timer that schedules a job to run every X seconds.

  • Improve this Doc
In This Article
Back to top Generated by DocFX