protected virtual void RunInBackground(BackgroundOperationType operationType) { if (_Worker != null && !_Worker.IsBusy) { BackgroundOperationArgs args = new BackgroundOperationArgs(operationType); RunInBackground(args); } }
protected virtual void RunInBackground <T>(BackgroundOperationType operationType, T args) { if (_Worker != null && !_Worker.IsBusy) { BackgroundOperationArgs <T> opArgs = new BackgroundOperationArgs <T>(args, operationType); _Worker.RunWorkerAsync(opArgs); } }
private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { BackgroundOperationType backgroundOperationType = (BackgroundOperationType)e.Argument; try { if (backgroundOperationType == BackgroundOperationType.CheckNewVersionAvailable) { _newVersionAvailable = PassportPDFApplicationUpdateUtilities.IsNewVersionAvailable(_appId, _appVersion, out string latestVersion); _latestVersionNumber = latestVersion; } else if (backgroundOperationType == BackgroundOperationType.CheckCurrentAppVersionIsSupported) { _currentAppVersionIsSupported = PassportPDFApplicationUpdateUtilities.IsCurrentApplicationVersionSupported(_appId, _appVersion); } else if (backgroundOperationType == BackgroundOperationType.FetchPassportInfo) { PassportPDFPassport passportPdfPassport = PassportPDFRequestsUtilities.GetPassportInfo(_passportToBeFetchedId); if (passportPdfPassport != null) { _fetchedPassportInfo = new PassportInfo { PassportNumber = passportPdfPassport.PassportId, IsActive = passportPdfPassport.IsActive, SubscriptionDate = passportPdfPassport.SubscriptionDate ?? default, TokensUsed = passportPdfPassport.CurrentTokensUsed, RemainingTokens = passportPdfPassport.RemainingTokens, }; } } else if (backgroundOperationType == BackgroundOperationType.FetchConfiguration) { FrameworkGlobals.FetchPassportPDFConfigurationEx(_appId); } else if (backgroundOperationType == BackgroundOperationType.FetchOCRSupportedLanguages) { _getAvailableOCRLanguagesResponse = PassportPDFRequestsUtilities.GetAvailableOCRLanguages(); } } catch (Exception exception) { _apiCallException = exception; } }
public BackgroundOperationArgs(BackgroundOperationType type) { Type = type; }
public BackgroundOperationResult(bool success, BackgroundOperationType type, string message = "") { Success = success; Type = type; Message = message; }