public void abortSync() { if (ntpRTTIntervalTimer != null) { ntpRTTIntervalTimer.Stop(); } if (ntpQueryTimer != null) { ntpQueryTimer.Stop(); } ntpResponseMonitor.Stop(); }
/// <summary> /// Stops the <see cref="DispatcherTimer"/>. /// </summary> public void Stop() { #if __ANDROID__ || __UNIFIED__ || WIN32 _timer.Stop(); #elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE _dispatcherTimer.Stop(); #endif }
public void Cleaning() { CleanupCameraAsync(); if (timer != null && timer.IsEnabled) { timer.Stop(); } }
internal void AddMouseUp() { const double minDistanceForClickDownAndUp = 0.1; if (IsRunning) { if (GetLength(mousePosition(), LastDownClickPosition) > minDistanceForClickDownAndUp) { //it is not a click UpCount = 0; DownCount = 0; clickTimer.Stop(); IsRunning = false; } else { UpCount++; } } }
public override void startTimer(long timeout, System.Action callback) { if (!(callback != null)) { return; } var dt = new Windows.UI.Xaml.DispatcherTimer(); dt.Interval = new System.TimeSpan(0, 0, 0, 0, (int)timeout); dt.Tick += (object sender, object e) => { callback(); dt.Stop(); }; dt.Start(); }
private void UpdateMediaState(PlayState state) { _lastKnownState = state; _timeOfLastKnownState = DateTime.Now; var _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (state.State == MediaState.Playing) { if (!_positionTimer.IsEnabled) { _positionTimer.Start(); } } else { _positionTimer.Stop(); } }); OnPropertyChanged(nameof(CurrentMedia), nameof(NextMedia), nameof(MediaState), nameof(Position)); }
private void AttemptLoginCommandAction() { LoginButtonLabel = "Logging in ..."; IsAttemptingLogin = true; LoginUserNameEnabled = false; LoginPasswordEnabled = false; Windows.UI.Xaml.DispatcherTimer dtDummyLoginAttempt = new Windows.UI.Xaml.DispatcherTimer(); dtDummyLoginAttempt.Interval = TimeSpan.FromSeconds(3); dtDummyLoginAttempt.Tick += (o, e) => { dtDummyLoginAttempt.Stop(); LoginButtonLabel = "Success"; IsAttemptingLogin = false; HideLoginCommand.Execute(null); SendInformationNotification("Pinch/Zoom to resize desktop", 3); }; dtDummyLoginAttempt.Start(); }
public static async Task <bool> setWallpaper(string filename) { StorageFolder fold = Windows.Storage.ApplicationData.Current.LocalFolder; var file = await fold.GetFileAsync(filename); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; //bool success = await profileSettings.TrySetLockScreenImageAsync(file); bool success = await profileSettings.TrySetWallpaperImageAsync(file); var timer = new Windows.UI.Xaml.DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) }; timer.Tick += (sender, args) => { MainPage.initTitlebar(); timer.Stop(); }; timer.Start(); return(success); }
/// <summary> /// Handles a failed connection to a server. /// This method can be overrided to implement a custom failover handling /// </summary> /// <param name="server">The failed server</param> internal protected virtual void HandleFailover(ReplicationServer server) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object sender, DoWorkEventArgs e) { bool isRunning = false; ReplicationServer server1 = e.Argument as ReplicationServer; #if !RT System.Timers.Timer timer = new System.Timers.Timer(RetryTime * 1000.0); System.Timers.ElapsedEventHandler elapsedEvent = delegate(object sender1, System.Timers.ElapsedEventArgs e1) { if (isRunning) { return; } try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(MySqlResources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Elapsed += elapsedEvent; timer.Start(); elapsedEvent(sender, null); #else Windows.UI.Xaml.DispatcherTimer timer = new Windows.UI.Xaml.DispatcherTimer(); TimeSpan ts = new TimeSpan(RetryTime * 1000); System.EventHandler <object> elapsedEvent = (TickSender, TickEventArgs) => { if (isRunning) { return; } try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.MySqlResources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Tick += elapsedEvent; elapsedEvent(sender, null); timer.Start(); #endif }; worker.RunWorkerAsync(server); }
/// <summary> /// Assigns a new server driver to the connection object /// </summary> /// <param name="groupName">Group name</param> /// <param name="master">True if the server connection to assign must be a master</param> /// <param name="connection">MySqlConnection object where the new driver will be assigned</param> public static void GetNewConnection(string groupName, bool master, MySqlConnection connection) { do { if (!IsReplicationGroup(groupName)) { return; } ReplicationServerGroup group = GetGroup(groupName); ReplicationServer server = group.GetServer(master); if (server == null) { throw new MySqlException(Properties.Resources.Replication_NoAvailableServer); } Driver driver = Driver.Create(new MySqlConnectionStringBuilder(server.ConnectionString)); if (connection.driver == null || driver.Settings.ConnectionString != connection.driver.Settings.ConnectionString) { connection.Close(); connection.hasBeenOpen = false; try { connection.driver = driver; connection.Open(); return; } catch (Exception) { // retry to open a failed connection and update its status connection.driver = null; server.IsAvailable = false; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object sender, DoWorkEventArgs e) { bool isRunning = false; ReplicationServer server1 = e.Argument as ReplicationServer; int retryTime = ReplicationManager.GetGroup(groupName).RetryTime; #if !RT System.Timers.Timer timer = new System.Timers.Timer(retryTime * 1000.0); System.Timers.ElapsedEventHandler elapsedEvent = delegate(object sender1, System.Timers.ElapsedEventArgs e1) { if (isRunning) { return; } try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Elapsed += elapsedEvent; timer.Start(); elapsedEvent(sender, null); #else Windows.UI.Xaml.DispatcherTimer timer = new Windows.UI.Xaml.DispatcherTimer(); TimeSpan ts = new TimeSpan(retryTime * 1000); System.EventHandler <object> elapsedEvent = (TickSender, TickEventArgs) => { if (isRunning) { return; } try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Tick += elapsedEvent; elapsedEvent(sender, null); timer.Start(); #endif }; worker.RunWorkerAsync(server); } } else { return; } } while (true); }
/// <summary> /// Handles a failed connection to a server. /// This method can be overrided to implement a custom failover handling /// </summary> /// <param name="server">The failed server</param> internal protected virtual void HandleFailover(ReplicationServer server) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object sender, DoWorkEventArgs e) { bool isRunning = false; ReplicationServer server1 = e.Argument as ReplicationServer; #if !RT System.Timers.Timer timer = new System.Timers.Timer(RetryTime * 1000.0); System.Timers.ElapsedEventHandler elapsedEvent = delegate(object sender1, System.Timers.ElapsedEventArgs e1) { if (isRunning) return; try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Elapsed += elapsedEvent; timer.Start(); elapsedEvent(sender, null); #else Windows.UI.Xaml.DispatcherTimer timer = new Windows.UI.Xaml.DispatcherTimer(); TimeSpan ts = new TimeSpan(RetryTime * 1000); System.EventHandler<object> elapsedEvent = (TickSender, TickEventArgs) => { if (isRunning) return; try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Tick += elapsedEvent; elapsedEvent(sender, null); timer.Start(); #endif }; worker.RunWorkerAsync(server); }
private void TimerTickEventhandler(object sender, object e) { if (_lastPaused != Paused) { _lastPaused = Paused; OnPropertyChanged("Paused"); } if (!Paused) { if (_leftAction.HasValue && _righrAction.HasValue) // jesli jednoczesnie zrobil 2 akcje wybierz pozniejsze zdarzenie { if (DateTime.Compare((DateTime)_leftAction, (DateTime)_righrAction) > 0) //jesli akcja 'w prawo' byla wczesniej idz w lewo { _model.MovePlayer(Direction.Left); } else // jesli pozniej w prawo { _model.MovePlayer(Direction.Right); } } if (_leftAction.HasValue)//ruch w lewo { _model.MovePlayer(Direction.Left); } if (_righrAction.HasValue)//ruch w prawo { _model.MovePlayer(Direction.Right); } } _model.Update(Paused); if (Score != _model.Score)//sprawdzamy score { Score = _model.Score; OnPropertyChanged("Score"); } if (_model.Lives >= 0)// aktualizacja _lives gracza { while (_model.Lives > _lives.Count) { _lives.Add(new object()); } while (_model.Lives < _lives.Count) { _lives.RemoveAt(0); } } foreach (FrameworkElement control in _shotInvaders.Keys.ToList())//jesli invader zostal zniszczony, to po animacji niszczenia(0.5s) jest usuwany po 0.5s { if (DateTime.Now - _shotInvaders[control] > TimeSpan.FromSeconds(0.5)) { _sprites.Remove(control); _shotInvaders.Remove(control); } } if (_model.GameOver)//jesli gra sie skonczyla zatrzymujemy stoper i zglaszamy GameOver w viewModel { _timer.Stop(); OnPropertyChanged("GameOver"); } }
/// <summary> /// Assigns a new server driver to the connection object /// </summary> /// <param name="groupName">Group name</param> /// <param name="master">True if the server connection to assign must be a master</param> /// <param name="connection">MySqlConnection object where the new driver will be assigned</param> public static void GetNewConnection(string groupName, bool master, MySqlConnection connection) { do { if (!IsReplicationGroup(groupName)) return; ReplicationServerGroup group = GetGroup(groupName); ReplicationServer server = group.GetServer(master); if (server == null) throw new MySqlException(Properties.Resources.Replication_NoAvailableServer); Driver driver = Driver.Create(new MySqlConnectionStringBuilder(server.ConnectionString)); if (connection.driver == null || driver.Settings.ConnectionString != connection.driver.Settings.ConnectionString) { connection.Close(); connection.hasBeenOpen = false; try { connection.driver = driver; connection.Open(); return; } catch (Exception) { // retry to open a failed connection and update its status connection.driver = null; server.IsAvailable = false; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object sender, DoWorkEventArgs e) { bool isRunning = false; ReplicationServer server1 = e.Argument as ReplicationServer; int retryTime = ReplicationManager.GetGroup(groupName).RetryTime; #if !RT System.Timers.Timer timer = new System.Timers.Timer(retryTime * 1000.0); System.Timers.ElapsedEventHandler elapsedEvent = delegate(object sender1, System.Timers.ElapsedEventArgs e1) { if (isRunning) return; try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Elapsed += elapsedEvent; timer.Start(); elapsedEvent(sender, null); #else Windows.UI.Xaml.DispatcherTimer timer = new Windows.UI.Xaml.DispatcherTimer(); TimeSpan ts = new TimeSpan(retryTime * 1000); System.EventHandler<object> elapsedEvent = (TickSender, TickEventArgs) => { if (isRunning) return; try { isRunning = true; using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString)) { connectionFailed.Open(); server1.IsAvailable = true; timer.Stop(); } } catch { MySqlTrace.LogWarning(0, string.Format(Properties.Resources.Replication_ConnectionAttemptFailed, server1.Name)); } finally { isRunning = false; } }; timer.Tick += elapsedEvent; elapsedEvent(sender, null); timer.Start(); #endif }; worker.RunWorkerAsync(server); } } else return; } while (true); }
private void AttemptLoginCommandAction() { LoginButtonLabel = "Logging in ..."; IsAttemptingLogin = true; LoginUserNameEnabled = false; LoginPasswordEnabled = false; Windows.UI.Xaml.DispatcherTimer dtDummyLoginAttempt = new Windows.UI.Xaml.DispatcherTimer(); dtDummyLoginAttempt.Interval = TimeSpan.FromSeconds(3); dtDummyLoginAttempt.Tick += (o,e) => { dtDummyLoginAttempt.Stop(); LoginButtonLabel = "Success"; IsAttemptingLogin = false; HideLoginCommand.Execute(null); SendInformationNotification("Pinch/Zoom to resize desktop", 3); }; dtDummyLoginAttempt.Start(); }
private void DispatcherTimer_Tick(object sender, EventArgs e) #endif { _dispatcherTimer.Stop(); _action?.Invoke(); }
public async void captureAudio(string options) { try { try { string args = JSON.JsonHelper.Deserialize <string[]>(options)[0]; this.captureAudioOptions = String.IsNullOrEmpty(args) ? CaptureAudioOptions.Default : JSON.JsonHelper.Deserialize <CaptureAudioOptions>(args); } catch (Exception ex) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } var mediaCaputreSettings = new MediaCaptureInitializationSettings(); mediaCaputreSettings.StreamingCaptureMode = StreamingCaptureMode.Audio; audioCaptureTask = new MediaCapture(); await audioCaptureTask.InitializeAsync(mediaCaputreSettings); var mediaEncodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto); var storageFile = await KnownFolders.MusicLibrary.CreateFileAsync("captureAudio.mp3", CreationCollisionOption.GenerateUniqueName); var timer = new Windows.UI.Xaml.DispatcherTimer(); timer.Tick += async delegate(object sender, object e) { timer.Stop(); await audioCaptureTask.StopRecordAsync(); if (storageFile != null) { long size = 0; string modifiedDate = ""; var tasks = new List <Task <BasicProperties> >(); tasks.Add(storageFile.GetBasicPropertiesAsync().AsTask()); var result = await Task.WhenAll(tasks); foreach (var prop in result) { size = (long)prop.Size; modifiedDate = prop.DateModified.ToString(); } string imagePathOrContent = string.Empty; var readStream = await storageFile.OpenAsync(FileAccessMode.Read); var inputStream = readStream.GetInputStreamAt(0); var dataReaderFile = new DataReader(inputStream); var numByteLoaded = await dataReaderFile.LoadAsync((uint)readStream.Size); var byteString = new byte[numByteLoaded]; var imageBase64String = ""; dataReaderFile.ReadBytes(byteString); imageBase64String = Convert.ToBase64String(byteString); imagePathOrContent = "data:audio/mpeg;base64," + imageBase64String; MediaFile data = new MediaFile(imagePathOrContent, storageFile.ContentType, storageFile.Name, size, modifiedDate); this.files.Add(data); if (files.Count < this.captureAudioOptions.Limit) { //dosomething here } else { DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files)); files.Clear(); } } }; timer.Interval = TimeSpan.FromMilliseconds(captureAudioDuration * 1000); await audioCaptureTask.StartRecordToStorageFileAsync(mediaEncodingProfile, storageFile); timer.Start(); } catch (Exception ex) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message)); } }