Created
April 19, 2022 11:38
-
-
Save bbenetskyy/ce10b10784c072d230eafc3ab56fccda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Android Background Worker | |
/// </summary> | |
public class BackgroundWork : Worker | |
{ | |
#region Fields | |
private ILogger _logger; | |
private IBackgroundWorkManager _backgroundWorkManager; | |
#endregion Fields | |
#region Contstoctors | |
public BackgroundWork(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) | |
{ | |
} | |
public BackgroundWork(Context context, WorkerParameters workerParams) : base(context, workerParams) | |
{ | |
} | |
#endregion Contstoctors | |
#region Properties | |
private ILogger Logger => _logger ??= Mvx.IoCProvider.Resolve<ILogger>(); | |
private IBackgroundWorkManager BackgroundWorkManager => _backgroundWorkManager ??= Mvx.IoCProvider.Resolve<IBackgroundWorkManager>(); | |
#endregion Properties | |
#region Public Methods | |
/// <summary> | |
/// Start Worker Background Work | |
/// </summary> | |
/// <returns>Work Result</returns> | |
public override Result DoWork() | |
{ | |
try | |
{ | |
BackgroundWorkManager.GetBackgroundWork() | |
.Invoke() | |
.Wait(); | |
Logger.LogEvent("BackgroundWork InvokeSuccess"); | |
return Result.InvokeSuccess(); | |
} | |
catch (Exception ex) | |
{ | |
Logger.LogError(ex); | |
Logger.LogEvent("BackgroundWork InvokeFailure"); | |
return Result.InvokeFailure(); | |
} | |
} | |
/// <summary> | |
/// When Worker Has Been Stopped | |
/// </summary> | |
public override void OnStopped() | |
{ | |
Logger.LogEvent("BackgroundWork OnStopped"); | |
base.OnStopped(); | |
} | |
#endregion Public Methods | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment