public void Clean() { if (baseDirectory == null) { throw new ArgumentException("A directory have to be selected"); } try { Starting?.Invoke(this, EventArgs.Empty); var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(() => ParseDirectory(baseDirectory), CancellationToken.None, TaskCreationOptions.None, taskScheduler).ContinueWith((t) => { Completed?.Invoke(this, EventArgs.Empty); }, taskScheduler); } catch (Exception ex) { Failed?.Invoke(this, ex); } }
public void PlayerLoop() { Starting?.Invoke(); event_idx = 0; play_delta_time = 0; while (true) { pause_handle.WaitOne(); if (do_stop) { break; } if (do_pause) { pause_handle.Reset(); do_pause = false; state = PlayerState.Paused; continue; } if (event_idx == messages.Count) { break; } ProcessMessage(messages [event_idx++]); } do_stop = false; Mute(); state = PlayerState.Stopped; if (event_idx == messages.Count) { PlaybackCompletedToEnd?.Invoke(); } Finished?.Invoke(); }
/// <summary> /// 开始监听 /// </summary> public void Start() { if (Running) { Log.Error(">正在监听中,重复的开始请求"); return; } Log.Info(">开始监听"); #if NETDNX AppDomain.CurrentDomain.ProcessExit -= CurrentDomain_ProcessExit; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; #else AppDomain.CurrentDomain.DomainUnload -= CurrentDomain_DomainUnload; AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; #endif Starting?.Invoke(this, EventArgs.Empty); if (Start_IPv4()) { System.Threading.Interlocked.CompareExchange(ref _running_v4, 1, 0); } if (Start_IPv6()) { System.Threading.Interlocked.CompareExchange(ref _running_v6, 1, 0); } Log.Info(">监听完成"); Started?.Invoke(this, EventArgs.Empty); if (Running) { StartAccept(); _beginTime = System.DateTime.Now; } }
private static void OnStarting(string[] args) { Starting?.Invoke(null, EventArgs.Empty); //激发当前上下文的“Starting”事件 _context.RaiseStarting(args); }
public void StartRandomTimer() { if (IsRunning) { Log.Debug($"Timer already running"); return; } Log.Debug($"Random start triggered at {DateTime.Now}"); IsRunning = true; var minimum = _propertyService.MinimumDelay; var window = minimum + _propertyService.StartWindow; Starting?.Invoke(this, EventArgs.Empty); var sleep = _random.Next(minimum, window); Log.Information($"Sleeping for {sleep}ms"); var timer = new CountDownTimer(TimeSpan.FromMilliseconds(sleep)); timer.ReachedZero += (_, __) => { Log.Information($"Start!"); Started?.Invoke(this, EventArgs.Empty); IsRunning = false; }; timer.Start(); }
private void StartSimulationOnConnectedPeers() { var writer = new Serializer(); //Create a new seed and send it with a start-message to all clients //The message also contains the respective player-id and the initial simulation speed var seed = new Random().Next(int.MinValue, int.MaxValue); Starting?.Invoke(this, new StartedEventArgs(SimulationSpeed, _actorIds.Values.ToArray())); foreach (var player in _actorIds) { writer.Reset(); writer.Put((byte)MessageTag.Init); new Init { Seed = seed, ActorID = player.Value, AllActors = _actorIds.Values.ToArray(), SimulationSpeed = SimulationSpeed }.Serialize(writer); _server.Send(player.Key, Compressor.Compress(writer)); } Started?.Invoke(this, new StartedEventArgs(SimulationSpeed, _actorIds.Values.ToArray())); }
private void MaybeStarted() { if (Interlocked.Exchange(ref _started, 1) == 0) { Starting?.Invoke(this, new EventArgs()); } }
protected virtual void OnStarting(Hero playerOne, Hero playerTwo) { Starting?.Invoke(this, new StartEventArgs() { PlayerOne = playerOne, PlayerTwo = playerTwo }); }
private void OnStarting(Object sender, EventArgs e) { _publishers.TryAddSubscriber(this); Starting?.Invoke(this, e); foreach (var series in _seriesProcessors) { series.IsStarted = true; } }
private void OnStarting() { Starting?.Invoke(this, EventArgs.Empty); _icon.Show(); _process.Start(); _process.BeginOutputReadLine(); _process.BeginErrorReadLine(); Application.Run(); }
/// <summary> /// 引发异步的 <see cref="Starting"/> 事件,并在事件的执行异步结束之后继续执行命令的其他部分。 /// </summary> protected override async Task <CommandStartingEventArgs> OnStarting() { var startingArgs = new CommandStartingEventArgs(); if (Starting != null) { await Starting.Invoke(this, startingArgs).ConfigureAwait(false); } return(startingArgs); }
public void Start() { if (Started) { Stop(); } Starting?.Invoke(); thread.Start(); }
private void OnStarting() { try { Starting?.Invoke(); } catch (Exception e) { _logger.Error("Starting event handler error", e); } }
public void Start() { //Clean up activeStates.Clear(); //Set up activeStates.AddLast(startState); startState.Activate(); //invoke the OnStart event which allows the user to add more functionality to the Start method Starting?.Invoke(this, EventArgs.Empty); }
public void Start() { transitioning = true; //start all processes foreach (var process in processes) { process.Start(); } Starting?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Start the background processing task, there may only be one running at a time. /// </summary> /// <exception cref="InvalidOperationException">Thrown if the task is running already.</exception> public void StartBackgroundTask() { if (!backgroundTask.IsCompleted) { throw new InvalidOperationException("The upload task is running already"); } taskCancellation = new CancellationTokenSource(); backgroundTask = ProcessQueue(taskCancellation.Token); Starting?.Invoke(this, EventArgs.Empty); backgroundTask.ContinueWith(HandleStoppingBackgroundTask); }
/// <summary> /// Starts updates on the dedicated thread. /// </summary> public void Start() { IsUpdating = true; Starting?.Invoke(this, EventArgs.Empty); shouldUpdate.Set(); if (!updateThread.IsAlive) { updateThread.Start(); } }
public void Start() { Starting?.Invoke(this, EventArgs.Empty); while (!IsHalted) { var result = Step(); if (result == ExecuteAction.Break) { Breaking?.Invoke(this, EventArgs.Empty); break; } } }
public virtual void Start() { if (isAlive) { return; } UpdateDriver.Add(this); isAlive = true; Starting?.Invoke(); StartingOneShot?.Invoke(); StartingOneShot = null; }
/// public void Initialize() { Starting?.Invoke(this, Initializables.Count()); //sort components to have an order var normalCmps = Initializables.Where(c => !(c is IPriorizedInitialize)).ToList(); var prioCmps = Initializables.Except(normalCmps).OrderBy(c => ((IPriorizedInitialize)c).RunLevel); var sortedComponents = new List <IInitializable>(); sortedComponents.AddRange(prioCmps); sortedComponents.AddRange(normalCmps); ThreadPool.QueueUserWorkItem(state => InitializeComponents(sortedComponents)); }
public CoreCoordinator(ITypeFinder typeFinder, IPublisherProvider publishers, IWorkerContainer workers) { _typeFinder = typeFinder; _publishers = publishers; _publishers.Starting += (sender, e) => Starting?.Invoke(sender, e); _publishers.Finishing += (sender, e) => Finishing?.Invoke(sender, e); _publishers.Finished += (sender, e) => Finished?.Invoke(sender, e); _publishers.ProgressChanged += (sender, e) => ProgressChanged?.Invoke(sender, e); _publishers.PublisherAdded += (o, e) => PublisherAdded?.Invoke(o, e); _publishers.Cancelling += (o, e) => Cancelling?.Invoke(o, e); _workers = workers; }
public void Start() { Logger.Info("AppHost: starting"); Starting?.Invoke(this, EventArgs.Empty); lock (_stateLock) { InternalStart(); State = HostState.Started; } Started?.Invoke(this, EventArgs.Empty); Logger.Info("AppHost: started"); }
/// <summary> /// 使用Headless Chrome访问给定地址 /// </summary> /// <param name="url">目标地址</param> /// <param name="operation">请求URL后等待完成的业务处理操作,如等待异步数据渲染到UI</param> /// <param name="script">执行JavaScript脚本(operation完成后执行)</param> public async Task Explore(string url, Operation operation, Script script) { if (string.IsNullOrWhiteSpace(url)) { return; } await Task.Run(() => { var watch = new Stopwatch(); watch.Start(); Starting?.Invoke(this, new ExploreStartingEventArgs(url)); try { //请求URL _chromeDriver.Navigate().GoToUrl(url); //执行JavaScript if (script != null) { _chromeDriver.ExecuteScript(script.Code, script.Args); } //返回条件和超时时间 if (operation?.Condition != null) { var driverWait = new WebDriverWait(_chromeDriver, TimeSpan.FromMilliseconds(operation.Timeout)); driverWait.Until(driver => operation.Condition.Invoke(driver)); operation.Action?.Invoke(_chromeDriver); } watch.Stop(); var threadId = Thread.CurrentThread.ManagedThreadId; var elapsed = watch.ElapsedMilliseconds; var pageSource = _chromeDriver.PageSource; Completed?.Invoke(this, new ExploreCompleteEventArgs(url, _chromeDriver, threadId, elapsed, pageSource)); } catch (Exception ex) { ExceptionlessUtil.Warn(ex, $"Browser访问{url}出错"); } }); }
public void Start() { // Validate ValidateUpdateAction(); // Notify starting Starting?.Invoke(this); // Actually start if (m_AsyncUpdateAction != null) { lock (m_AsyncUpdateAction) { if (m_Scheduled) { m_Scheduler.Resume(m_AsyncUpdateAction); } else { m_Scheduler.Schedule(m_AsyncUpdateAction, m_ScheduleOptions); m_Scheduled = true; } } } else { lock (m_UpdateAction) { if (m_Scheduled) { m_Scheduler.Resume(m_UpdateAction); } else { m_Scheduler.Schedule(m_UpdateAction, m_ScheduleOptions); m_Scheduled = true; } } } // Notify started m_IsStarted = true; Started?.Invoke(this); }
internal async void Start(string hearthstonePath, string logDirectory = "Logs") { if (_running) { return; } Starting?.Invoke(); var fullPath = Path.Combine(hearthstonePath, "Logs"); var startingPoint = GetStartingPoint(fullPath); Log.Debug($"Starting log readers in \"{fullPath}\", at [{startingPoint}]"); foreach (var logReader in _watchers) { logReader.Start(fullPath, logReader.Info.Name == "Decks" ? startingPoint.Decks : startingPoint.Default); } _running = true; _stop = false; var newLines = new SortedList <DateTime, List <Line> >(); while (!_stop) { await Task.Factory.StartNew(() => { foreach (var logReader in _watchers) { var lines = logReader.Collect(); foreach (var line in lines) { if (!newLines.TryGetValue(line.Time, out var logLines)) { newLines.Add(line.Time, logLines = new List <Line>()); } logLines.Add(line); } } }); NewLines?.Invoke(new NewLinesEventArgs(newLines.Values.SelectMany(x => x))); newLines.Clear(); await Task.Delay(UpdateDelay); } _running = false; }
/// <summary> /// 開始 /// </summary> public void Start() { if (_timer.Enabled == true) // 執行中就不動作 { return; } _timer.Enabled = true; // 啟動時, 可覆寫的方法 Starting?.Invoke(this, EventArgs.Empty); // 若是啟動, 需先執行一次動作 System.Threading.ThreadStart threadDelegate = new System.Threading.ThreadStart(TriggerTimedEvent); System.Threading.Thread thread = new System.Threading.Thread(threadDelegate); //System.Threading.Thread thread = new System.Threading.Thread(new delegate //{ // OnTimedEvent(this, null); //}); thread.Start(); }
private void TryStart() { if (State == AnimationState.Running || State == AnimationState.Rewinding) { return; } if (State == AnimationState.Paused) { _storyboard.Resume(); return; } var cancelArgs = new CancelEventArgs(); Starting?.Invoke(this, cancelArgs); if (cancelArgs.Cancel) { return; } _playingDuration = Duration; StartProgressAnimation(); }
protected override void OnStart() { base.OnStart(); Starting?.Invoke(this, EventArgs.Empty); }
private void Start() { Starting?.Invoke(); }
/// <summary> /// Invoked when the timer is starting. /// </summary> /// <param name="args"></param> protected void OnStarting(TimerEventArgs args) { Starting?.Invoke(this, args); }