public void DidScan(IScanSession session) { if (session.NewlyRecognizedCodes.Count > 0) { if (!ContinuousAfterScan) { // Call GC.Collect() before stopping the scanner as the garbage collector for some reason does not // collect objects without references asap but waits for a long time until finally collecting them. GC.Collect(); // Stop the scanner directly on the session. session.PauseScanning(); } // If you want to edit something in the view hierarchy make sure to run it on the UI thread. using (var h = new Android.OS.Handler(Android.OS.Looper.MainLooper)) { h.Post(() => { var symbologies = ""; var data = ""; foreach (var code in session.NewlyRecognizedCodes) { var separator = symbologies.Length == 0 ? "" : ", "; symbologies += separator + code.SymbologyName; data += separator + code.Data; } PickerView.DidScan(symbologies, data); }); } } }
void StartDownloadWatcher() { // Create an instance for a runnable-handler _downloadWatcherHandler = new Android.OS.Handler(); // Create a runnable, restarting itself to update every file in the queue _downloadWatcherHandlerRunnable = new Java.Lang.Runnable(() => { var downloads = Queue.Cast <DownloadFileImplementation>().ToList(); LoopOnDownloads(cursor => { int id = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnId)); var downloadFile = downloads.FirstOrDefault(f => f.Id == id); if (downloadFile != null) { downloads.Remove(downloadFile); UpdateFileProperties(cursor, downloadFile); } }); // All downloads still in this list are not listed in the native donload-manager of Android. Mark them as canceled. foreach (var file in downloads) { Abort(file); } _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 1000); }); // Start this playing handler immediately _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 0); }
void LoadMoreItems(uint count, int baseIndex) { BackgroundWorker worker = new BackgroundWorker(); //worker.RunWorkerAsync (); worker.DoWork += (o, ae) => { DataServiceQuery <Order> query = northwindEntity.Orders.Expand("Customer"); query = query.Skip <Order>(baseIndex).Take <Order>(50) as DataServiceQuery <Order>; IAsyncResult ar = query.BeginExecute(null, null); var items = query.EndExecute(ar); var list = items.ToList(); Android.OS.Handler mainHandler = new Android.OS.Handler(Android.OS.Looper.MainLooper); Java.Lang.Runnable myRunnable = new Java.Lang.Runnable(() => { GridSource.LoadItems(list); }); mainHandler.Post(myRunnable); }; worker.RunWorkerCompleted += (o, ae) => { IsBusy = false; }; IsBusy = true; worker.RunWorkerAsync(); }
private Android.OS.Handler getBackgroundHandler() { if (mBackgroundHandler == null) { Android.OS.HandlerThread backgroundThread = new Android.OS.HandlerThread("catwindow", (int)Android.OS.ThreadPriority.Background); backgroundThread.Start(); mBackgroundHandler = new Android.OS.Handler(backgroundThread.Looper); } return(mBackgroundHandler); }
public override void OnCreate() { Log.Info(TAG, "OnCreate"); base.OnCreate(); dispatcher = MessageDispatcher.GetInstance(); dispatcher.Subscribe(MessageType.MotionUpdate, this); extendedMotionHandler = new Android.OS.Handler(Android.OS.Looper.MainLooper); extendedMotionCallback = delegate { RunActiveGestures(); }; }
private static void StartAnimationLoop() { #if __ANDROID__ Action init = () => { if (timeAnimator == null) { timeAnimator = new Android.Animation.TimeAnimator() { RepeatCount = Android.Animation.ValueAnimator.Infinite }; timeAnimator.Time += (s, e) => OnFrameEvent(TimeSpan.FromMilliseconds(e.TotalTime)); } timeAnimator.CurrentPlayTime = 0; timeAnimator.Start(); }; if (Android.OS.Looper.MainLooper.IsCurrentThread) { init(); } else { using (var h = new Android.OS.Handler(Android.OS.Looper.MainLooper)) { h.Post(init); } } #elif __IOS__ if (_displayLink == null) { _displayLink = CoreAnimation.CADisplayLink.Create(() => OnFrameEvent(TimeSpan.FromSeconds(_displayLink.Timestamp))); _displayLink.AddToRunLoop(Foundation.NSRunLoop.Main, Foundation.NSRunLoop.NSDefaultRunLoopMode); } #elif NETFX_CORE if (Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess) { CompositionTarget.Rendering += CompositionTargetRendering; } else { var _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => CompositionTarget.Rendering += CompositionTargetRendering); } #else if (System.Windows.Application.Current.Dispatcher.CheckAccess()) { CompositionTarget.Rendering += CompositionTargetRendering; } else { System.Windows.Application.Current.Dispatcher.Invoke(() => CompositionTarget.Rendering += CompositionTargetRendering); } #endif }
public static Task OnMainThread(Action action) { var tcs = new TaskCompletionSource <bool>(); var looper = Android.OS.Looper.MainLooper; var handler = new Android.OS.Handler(looper); handler.Post(() => { action(); tcs.SetResult(true); }); return(tcs.Task); }
/// <summary> /// check clipboard once while top activity switched to keysetting /// </summary> protected override void OnAppearing() { Android.OS.Handler a = new Android.OS.Handler(); a.Post(() => { CheckClipboard(); }); /* * a.PostDelayed(() => * { * CheckClipboard(); * }, 1000);*/ }
void StartDownloadWatcher() { // Create an instance for a runnable-handler _downloadWatcherHandler = new Android.OS.Handler(); // Create a runnable, restarting itself to update every file in the queue _downloadWatcherHandlerRunnable = new Java.Lang.Runnable(() => { // Loop throught all files in the system-queue and update the data in the local queue LoopOnDownloads(cursor => UpdateFileProperties(cursor)); _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 1000); }); // Start this playing handler immediately _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 0); }
private void Initialize() { _uithread = new Android.OS.Handler(Context !.MainLooper !); _listView = new ListView(Context) { ClipToOutline = true, Clickable = false, ChoiceMode = ChoiceMode.None, LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent), ScrollingCacheEnabled = false, PersistentDrawingCache = PersistentDrawingCaches.NoCache, }; AddView(_listView); }
public static Task OnMainThread(Func <Task> action) { var tcs = new TaskCompletionSource <bool>(); var looper = Android.OS.Looper.MainLooper; var handler = new Android.OS.Handler(looper); handler.Post(async() => { try { await action(); tcs.SetResult(true); } catch (Exception ex) { tcs.SetException(ex); } }); return(tcs.Task); }
private void RunOnUIThread(Action action) { #if NETFX_CORE if (Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess) { action(); } else { var _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => action()); } #elif __ANDROID__ if (Android.OS.Looper.MainLooper.IsCurrentThread) { action(); } else { using (var h = new Android.OS.Handler(Android.OS.Looper.MainLooper)) { h.Post(action); } } #elif __IOS__ action(); #else var dispatcher = System.Windows.Application.Current.Dispatcher; if (dispatcher == null || dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished) { return; // Occurs during shutdown } if (dispatcher.CheckAccess()) { action(); } else { dispatcher.Invoke(action); } #endif }
/// <summary> /// check clipboard once while top activity switched to mainpage(not from KeySetting page) /// </summary> protected override void OnAppearing() { base.OnAppearing(); if (KeySetting.BackFromSetting) { KeySetting.BackFromSetting = false; } else { Android.OS.Handler a = new Android.OS.Handler(); a.Post(() => { CheckClipboard(); }); /* * a.PostDelayed(() => * { * CheckClipboard(); * }, 1000);*/ } }
void StartDownloadWatcher() { // Create an instance for a runnable-handler _downloadWatcherHandler = new Android.OS.Handler(); // Create a runnable, restarting itself to update every file in the queue _downloadWatcherHandlerRunnable = new Java.Lang.Runnable(() => { var downloads = Queue.Cast <DownloadFileImplementation>().ToList(); foreach (var file in downloads) { var query = new Android.App.DownloadManager.Query(); query.SetFilterById(file.Id); try { using (var cursor = _downloadManager.InvokeQuery(query)) { if (cursor != null && cursor.MoveToNext()) { UpdateFileProperties(cursor, file); } else { // This file is not listed in the native download manager anymore. Let's mark it as canceled. Abort(file); } cursor?.Close(); } } catch (Android.Database.Sqlite.SQLiteException) { // I lately got an exception that the database was unaccessible ... } } _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 1000); }); // Start this playing handler immediately _downloadWatcherHandler.PostDelayed(_downloadWatcherHandlerRunnable, 0); }
void ReadInternal() { if (Configuration.IsForceUI) { using (var h = new Handler(Looper.MainLooper)) { h.Post(() => { if (!_gatt.ReadCharacteristic(_nativeCharacteristic)) { throw new CharacteristicReadException("BluetoothGattCharacteristic.readCharacteristic returned FALSE"); } }); } } else { if (!_gatt.ReadCharacteristic(_nativeCharacteristic)) { throw new CharacteristicReadException("BluetoothGattCharacteristic.readCharacteristic returned FALSE"); } } }
private static void StopAnimationLoop() { #if __ANDROID__ if (Android.OS.Looper.MainLooper.IsCurrentThread) { timeAnimator?.Cancel(); } else { using (var h = new Android.OS.Handler(Android.OS.Looper.MainLooper)) { h.Post(() => timeAnimator?.Cancel()); } } #elif __IOS__ _displayLink?.Invalidate(); _displayLink = null; #elif NETFX_CORE if (Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess) { CompositionTarget.Rendering -= CompositionTargetRendering; } else { var _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => CompositionTarget.Rendering -= CompositionTargetRendering); } #else if (System.Windows.Application.Current.Dispatcher.CheckAccess()) { CompositionTarget.Rendering -= CompositionTargetRendering; } else { System.Windows.Application.Current.Dispatcher.Invoke(() => CompositionTarget.Rendering -= CompositionTargetRendering); } #endif }
private void InternalWrite(byte[] data) { if (Configuration.IsForceUI) { using (var h = new Handler(Looper.MainLooper)) { h.Post(() => { if (!_nativeCharacteristic.SetValue(data)) { throw new CharacteristicReadException("Gatt characteristic set value FAILED."); } Trace.Message("Write {0}", Id); if (!_gatt.WriteCharacteristic(_nativeCharacteristic)) { throw new CharacteristicReadException("Gatt write characteristic FAILED."); } }); } } else { if (!_nativeCharacteristic.SetValue(data)) { throw new CharacteristicReadException("Gatt characteristic set value FAILED."); } Trace.Message("Write {0}", Id); if (!_gatt.WriteCharacteristic(_nativeCharacteristic)) { throw new CharacteristicReadException("Gatt write characteristic FAILED."); } } }
public async Task <IContainerHolder> LoadContainerPreferNonDefaultAsync(string containerId, int defaultContainerResourceId, Android.OS.Handler handler) { return((await LoadContainerPreferNonDefault(containerId, defaultContainerResourceId, handler)).JavaCast <IContainerHolder>()); }
void LoadMoreItems (uint count, int baseIndex) { BackgroundWorker worker = new BackgroundWorker (); //worker.RunWorkerAsync (); worker.DoWork += (o, ae) => { DataServiceQuery<Order> query = northwindEntity.Orders.Expand ("Customer"); query = query.Skip<Order> (baseIndex).Take<Order> (50) as DataServiceQuery<Order>; IAsyncResult ar = query.BeginExecute (null, null); var items = query.EndExecute (ar); var list = items.ToList (); Android.OS.Handler mainHandler = new Android.OS.Handler (Android.OS.Looper.MainLooper); Java.Lang.Runnable myRunnable = new Java.Lang.Runnable (() => { GridSource.LoadItems (list); }); mainHandler.Post (myRunnable); }; worker.RunWorkerCompleted += (o, ae) => { IsBusy = false; }; IsBusy = true; worker.RunWorkerAsync (); }