public override void Invoke(CancellationToken token) { OnBegin?.Invoke(); var box = new List <List <TItem> > { new List <TItem>() }; var idx = 0; foreach (var item in Sources.GetConsumingEnumerable()) { token.ThrowIfCancellationRequested(); OnInterval?.Invoke(item); box[idx].Add(item); if (box[idx].Count != Size) { continue; } Results.Add(box[idx].ToArray(), token); idx++; box.Add(new List <TItem>()); } if (box[idx].Any()) { Results.Add(box[idx].ToArray(), token); } Results.CompleteAdding(); OnFinish?.Invoke(); }
public override void Invoke(CancellationToken token) { OnBegin?.Invoke(); var tasks = new List <Task>(); for (var i = 0; i < Workers; i++) { tasks.Add(Task.Factory.StartNew(() => { foreach (var source in Sources.GetConsumingEnumerable()) { token.ThrowIfCancellationRequested(); foreach (var result in filter(source)) { Results.Add(result, token); OnInnerInterval?.Invoke(result); } OnInterval?.Invoke(source); } }, token)); } Task.WaitAll(tasks.ToArray()); Results.CompleteAdding(); OnFinish?.Invoke(); }
public void Start(bool reverse) { IsReversed = _hasBegunReversed = reverse; TimeLeft = Duration; Value = Percent = IsReversed ? 1f : 0f; IsActive = true; OnBegin?.Invoke(this); }
public void Begin() { if (IsActive) { return; } IsActive = true; OnBegin?.Invoke(this, EventArgs.Empty); BeginImpl(); }
private void Initialize(Scene scene) { if (Initialized) { return; } Initialized = true; WrappedScene.Begin(); scene.RendererList.Add(Renderer); Renderer.Alloc(); OnBegin?.Invoke(WrappedScene); }
public void AwaitKeyPress() { OnBegin?.Invoke(); if (!string.IsNullOrWhiteSpace(Title)) { Console.Title = Title; } Console.BackgroundColor = Background; Console.Clear(); foreach (var group in Groups) { if (!string.IsNullOrWhiteSpace(group.Caption)) { Console.WriteLine(); Console.WriteLine(new string(' ', Indent) + group.Caption); } Console.WriteLine(); foreach (var item in group.Items) { if (!string.IsNullOrWhiteSpace(item.Caption)) { Console.WriteLine(new string(' ', Indent) + item.Caption.Replace("{key}", item.Key.ToString())); } } } Console.WriteLine(); Console.WriteLine(" " + new string('┈', Console.BufferWidth - 2) + " "); EndingCursorTop = Console.CursorTop; while (!exit) { var key = Console.ReadKey(true).Key; var menuItem = Groups.SelectMany(g => g.Items).SingleOrDefault(i => i.Key == key); if (menuItem != null) { if (menuItem.OnSelection == null) { exit = true; } else { menuItem.OnSelection.Invoke(); } } } OnEnd?.Invoke(); }
protected virtual void Initialize() { // systems initialization Debug.Console.Start(); OnBegin?.Invoke(); OnBegin = null; SwitchScene(StartSceneName); UpdateCurrentScene(); // late systems initialization Util.Tween.Tweener.Instance.Start(); }
public void Subscribe(EventHandler <TResponse> value) { OnData += value; Task.Run(async() => { using NamedPipeClientStream stream = new NamedPipeClientStream(pipeName); using StreamReader reader = new StreamReader(stream); using StreamWriter writer = new StreamWriter(stream); await stream.ConnectAsync(5000, _externCancellationToken).ConfigureAwait(false); await writer.WriteLineAsync(request.ToJson()).ConfigureAwait(false); await writer.FlushAsync().ConfigureAwait(false); stream.WaitForPipeDrain(); while (!_externCancellationToken.IsCancellationRequested && !unsubscribeToken.IsCancellationRequested) { string responsJson = await reader.ReadLineAsync().ConfigureAwait(false); StreamlabsOBSResponse response = JsonConvert.DeserializeObject <StreamlabsOBSResponse>(responsJson); response.JsonResponse = responsJson; if (response.Results.Value <string>("_type").Equals("SUBSCRIPTION")) { OnBegin?.Invoke(this, response); } else if (response.Results.Value <string>("_type").Equals("EVENT")) { StreamlabsOBSEvent eventData = response.GetResultFirstOrDefault <StreamlabsOBSEvent>(); OnEvent?.Invoke(this, eventData); if (typeof(TResponse).IsAssignableFrom(typeof(StreamlabsOBSEvent))) { OnData?.Invoke(this, eventData as TResponse); } else { OnData?.Invoke(this, eventData.GetDataFirstOrDefault <TResponse>()); } } else { OnUnsupported?.Invoke(this, responsJson); } } }, _externCancellationToken); }
/// <summary> /// Starts the game or round. Initializes the GameFlowHandler to begin the round. /// </summary> public virtual void Begin() { if (Game.RoundNumber == 0) { LastTurn = new GameBeginningTurn(PlayerOnTurn); } else { LastTurn = new GameTurn(PlayerOnTurn); } RedrawToPlayersPerspective(); OnBegin?.Invoke(); var factory = new GameBotFactory(); var bot = factory.CreateFromGame(Game, PlayerOnTurn, GameBotType.MonteCarloTreeSearchBot); //bot.FindBestMove(); }
public Exception Run(CancellationToken token, string logFile) { OnBegin?.Invoke(); // init logger Logger = new Logger.Logger(); if (!string.IsNullOrEmpty(logFile)) { Logger.AddHook(new FileHook(logFile)); } // Bind Vtn = new Transistor(Bind(VtnString, (VtnThreshold, VtnSigma, VtnNumberOfSigma), Sigma)); Vtp = new Transistor(Bind(VtpString, (VtpThreshold, VtpSigma, VtpNumberOfSigma), Sigma)); var rt = Do(token); OnFinish?.Invoke(); return(rt); }
public void Begin() { lives = 3; foreach (Image im in hearts) { im.color = heartCol; } skinnedMesh.materials[1].mainTexture = idle; skinnedMesh.materials[0].color = skinCol; score = 0; DisplayScore(); // if (mode == Difficulty.Easy) { // StartCoroutine(SpawnConstantly(()=>minSpeed + Mathf.Log(1+.01f*Time.time), // ()=>minDelay + (maxDelay-minDelay)/(1+.01f*Time.time))); // } else if (mode == Difficulty.Hard) { StartCoroutine(SpawnConstantly(() => minSpeed + (float)Math.Log(1 + Math.Sqrt(.01 * score)), () => minDelay + (maxDelay - minDelay) / (1 + (float)Math.Sqrt(.01f * score)))); // } OnBegin.Invoke(); }
//Public Methods: public void FireBegin() { Active = true; OnBegin?.Invoke(); }
private void BeginRound(object sender, EventArgs e) { OnBegin?.Invoke(); }
public virtual void Begin() { OnBegin?.Invoke(); }
public void Begin() { OnBegin?.Invoke(); }