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(); }
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); }); } } }
private void Layer_Loaded(object sender, System.EventArgs e) { if (sender is ILoadable loadable) { loadable.Loaded -= Layer_Loaded; } _uithread.Post(Refresh); }
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);*/ }
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 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."); } } }
private void Layer_Loaded(object sender, System.EventArgs e) { (sender as ILoadable).Loaded -= Layer_Loaded; _uithread.Post(Refresh); }
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 (); }