public async Task Start(StartLongRunningTaskMessage startLongRunningTaskMessage) { _cts = new CancellationTokenSource(); _taskId = UIApplication.SharedApplication.BeginBackgroundTask("LongRunningTask", OnExpiration); try { //INVOKE THE SHARED CODE var counter = new TaskCounter(); await counter.RunCounter(_cts.Token, startLongRunningTaskMessage.Barcode, startLongRunningTaskMessage.PageName); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(message, "CancelledMessage") ); } } UIApplication.SharedApplication.EndBackgroundTask(_taskId); }
public async Task Start() { _taskId = UIApplication.SharedApplication.BeginBackgroundTask("LongRunningTask", OnExpiration); _cts = new CancellationTokenSource(); try { var counter = new TaskCounter(); await counter.RunCounter(_cts.Token); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); MainThread.BeginInvokeOnMainThread(() => MessagingCenter.Send(message, nameof(CancelledMessage))); } } UIApplication.SharedApplication.EndBackgroundTask(_taskId); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { //INVOKE THE SHARED CODE var counter = new TaskCounter(); counter.RunCounter(_cts.Token).Wait(); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(message, "CancelledMessage") ); } } }, _cts.Token); return(StartCommandResult.Sticky); }
public override StartCommandResult OnStartCommand (Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource (); Task.Run (() => { try { //INVOKE THE SHARED CODE var counter = new TaskCounter(); counter.RunCounter(_cts.Token).Wait(); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread ( () => MessagingCenter.Send(message, "CancelledMessage") ); } } }, _cts.Token); return StartCommandResult.Sticky; }
public static Counters NewCounters() { Counters hc = new Counters(); foreach (JobCounter c in JobCounter.Values()) { hc.FindCounter(c).SetValue((long)(Math.Random() * 1000)); } foreach (TaskCounter c_1 in TaskCounter.Values()) { hc.FindCounter(c_1).SetValue((long)(Math.Random() * 1000)); } int nc = FileSystemCounter.Values().Length * 4; for (int i = 0; i < nc; ++i) { foreach (FileSystemCounter c_2 in FileSystemCounter.Values()) { hc.FindCounter(FsSchemes.Next(), c_2).SetValue((long)(Math.Random() * Dt)); } } for (int i_1 = 0; i_1 < 2 * 3; ++i_1) { hc.FindCounter(UserCounterGroups.Next(), UserCounters.Next()).SetValue((long)(Math .Random() * 100000)); } return(hc); }
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { // invoke the shared code with the task that needs to be performed in the background var counter = new TaskCounter(); counter.RunCounter(_cts.Token).Wait(); } catch (Exception ex) { } finally { if (_cts.IsCancellationRequested) { var message = new Messages.CancelledMessage(); Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(message, "CancelledMessage")); } } }); return(StartCommandResult.Sticky); }
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(async() => { try { var counter = new TaskCounter(); await counter.RunCounter(_cts.Token); } catch (Exception ex) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(message, MessagingNames.CancelledMessage); }); } } }); return(StartCommandResult.Sticky); }
public ArtifactCopyingVisitor(VirtualFileSystem fileSystem, IUserInteractionService userInteractionService, IPathValidator pathValidator, IApplicationController applicationController, TaskCounter taskCounter) { if (fileSystem == null) { throw new ArgumentNullException("fileSystem"); } if (userInteractionService == null) { throw new ArgumentNullException("userInteractionService"); } if (pathValidator == null) { throw new ArgumentNullException("pathValidator"); } if (applicationController == null) { throw new ArgumentNullException("applicationController"); } if (taskCounter == null) { throw new ArgumentNullException("taskCounter"); } _fileSystem = fileSystem; _applicationController = applicationController; _taskCounter = taskCounter; _userInteractionService = userInteractionService; _pathValidator = pathValidator; }
public async Task Start() { _cts = new CancellationTokenSource(); _taskId = UIApplication.SharedApplication.BeginBackgroundTask(taskName, OnExpiration); try { var counter = new TaskCounter(); await counter.RunCounter(_cts.Token); } catch (Exception ex) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(message, MessagingNames.CancelledMessage); }); } } UIApplication.SharedApplication.EndBackgroundTask(_taskId); }
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { var counter = new TaskCounter(); counter.RunCounter(_cts.Token).Wait(); } catch (Android.OS.OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); MainThread.BeginInvokeOnMainThread(() => MessagingCenter.Send(message, nameof(CancelledMessage))); } } }, _cts.Token); return(StartCommandResult.Sticky); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); var counter = new TaskCounter(); counter.RunCounter("1"); return(StartCommandResult.Sticky); }
private void DisplayBrowserViewModel(string fullPathForFile, VirtualFileSystem newVirtualFileSystem) { var nameValidator = FileSystemArtifactNamesValidator.Default; var stuffDeletingVisitor = new ArtifactDeletingVisitor(newVirtualFileSystem, _userInteractionService); var stuffRenamingVisitor = new ArtifactRenamingVisitor(newVirtualFileSystem, _userInteractionService, nameValidator); var stuffMovingVisitor = new ArtifactMovingVisitor(newVirtualFileSystem, _userInteractionService, PathValidator.Default); var newArtifactCreator = new NewArtifactCreator(newVirtualFileSystem, _userInteractionService); TaskCounter taskCounter = new TaskCounter(); var importer = new ArtifactImporter(newVirtualFileSystem, VirtualFileSystemInstanceManager, taskCounter); _applicationController.DisplayNewBrowserWindow( new BrowserWindowViewModel(newVirtualFileSystem, _applicationController, _viewModelComparer, _userInteractionService, fullPathForFile, StringComparer.OrdinalIgnoreCase, stuffDeletingVisitor, nameValidator, stuffRenamingVisitor, newArtifactCreator, VirtualFileSystemInstanceManager, stuffMovingVisitor, importer, taskCounter, _dispatcher)); }
private void RunTasks() { Trace.WriteLineIf(Tracing.Is.TraceVerbose, string.Empty); try { foreach (var export in new CompositionContainer(AllCatalogs).GetExports <ITask>()) { var task = export.Value; if (null == task) { continue; } Trace.WriteLineIf(Tracing.Is.TraceVerbose, Resources.TaskManager_TaskGetTypeFullName.FormatWith(task.GetType().FullName)); var factory = new TaskFactory(Cancellation.Token, task.CreationOptions, task.ContinuationOptions, TaskScheduler.Default); factory.StartNew(() => task.Run(Cancellation.Token)); TaskCounter.Increment(); } } catch (ReflectionTypeLoadException exception) { Trace.TraceError("{0}".FormatWith(exception)); Trace.Indent(); if (null != exception.LoaderExceptions) { foreach (var item in exception.LoaderExceptions) { Trace.TraceError("{0}".FormatWith(item)); } } Trace.Unindent(); } catch (Exception exception) { Trace.TraceError("{0}".FormatWith(exception)); } }
public async Task Start () { _cts = new CancellationTokenSource (); _taskId = UIApplication.SharedApplication.BeginBackgroundTask ("LongRunningTask", OnExpiration); try { //INVOKE THE SHARED CODE var counter = new TaskCounter(); await counter.RunCounter(_cts.Token); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread ( () => MessagingCenter.Send(message, "CancelledMessage") ); } } UIApplication.SharedApplication.EndBackgroundTask (_taskId); }
public BrowserWindowViewModel( VirtualFileSystem virtualSystemCurrentlyBrowsed, IApplicationController applicationController, IComparer <FileSystemArtifactViewModel> viewModelSortingComparer, IUserInteractionService userInteractionService, string diskBrowsedLocation, IEqualityComparer <string> fileSystemArtifactNameComparer, IFileSystemArtifactViewModelVisitor deletingVisitor, IFileSystemArtifactNamesValidator artifactNamesValidator, IFileSystemArtifactViewModelVisitor renamingVisitor, INewArtifactCreator newArtifactCreator, IVirtualFileSystemInstanceManager virtualFileSystemInstanceManager, IFileSystemArtifactViewModelVisitor movingVisitor, IArtifactImporter artifactImporter, TaskCounter taskCounter, IDispatcher dispatcher) { if (virtualSystemCurrentlyBrowsed == null) { throw new ArgumentNullException("virtualSystemCurrentlyBrowsed"); } if (applicationController == null) { throw new ArgumentNullException("applicationController"); } if (viewModelSortingComparer == null) { throw new ArgumentNullException("viewModelSortingComparer"); } if (userInteractionService == null) { throw new ArgumentNullException("userInteractionService"); } if (diskBrowsedLocation == null) { throw new ArgumentNullException("diskBrowsedLocation"); } if (fileSystemArtifactNameComparer == null) { throw new ArgumentNullException("fileSystemArtifactNameComparer"); } if (deletingVisitor == null) { throw new ArgumentNullException("deletingVisitor"); } if (artifactNamesValidator == null) { throw new ArgumentNullException("artifactNamesValidator"); } if (renamingVisitor == null) { throw new ArgumentNullException("renamingVisitor"); } if (newArtifactCreator == null) { throw new ArgumentNullException("newArtifactCreator"); } if (virtualFileSystemInstanceManager == null) { throw new ArgumentNullException("virtualFileSystemInstanceManager"); } if (movingVisitor == null) { throw new ArgumentNullException("movingVisitor"); } if (artifactImporter == null) { throw new ArgumentNullException("artifactImporter"); } if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } this.CurrentFolderContents = new ObservableCollection <FileSystemArtifactViewModel>(); _virtualSystemCurrentlyBrowsed = virtualSystemCurrentlyBrowsed; _taskCounter = taskCounter; _dispatcher = dispatcher; _artifactImporter = artifactImporter; _movingVisitor = movingVisitor; _renamingVisitor = renamingVisitor; _newArtifactCreator = newArtifactCreator; _virtualFileSystemInstanceManager = virtualFileSystemInstanceManager; _userInteractionService = userInteractionService; _diskBrowsedLocation = diskBrowsedLocation; _fileSystemArtifactNameComparer = fileSystemArtifactNameComparer; _deletingVisitor = deletingVisitor; _artifactNamesValidator = artifactNamesValidator; _applicationController = applicationController; _viewModelSortingComparer = viewModelSortingComparer; this.CurrentFolderPath = VirtualFileSystem.Root; _tasks = new ObservableCollection <TaskViewModel>(); this.Tasks = new ReadOnlyObservableCollection <TaskViewModel>(_tasks); this.RefreshCurrentFolderContentsFallingBackToRootIfNecessary(); this.FileSearchPattern = new FileSearchPatternViewModel(); this.IsRefreshEnabled = true; }