public void Ctor() { // given AppTimer timer1 = new AppTimer(); IList <string> times1 = new List <string>(); // when timer1.OnCount += (object sender, OnCountEventArgs e) => { times1.Add(e.Time); }; timer1.Start(); Thread.Sleep(6_000); timer1.Start(); // then Assert.IsTrue(times1.Count == 5); }
public About() { InitializeComponent(); IsFormShown = false; timer = new AppTimer(); timer.OnCount += new EventHandler <OnCountEventArgs>(OnTimerCount); LocalizeWindow(); UpdateUiBySettings(); timer.Start(); }
public static void StartRefreshDeviceListViewTimer() { if (_refreshDeviceListViewTimer?.IsActive ?? false) { return; } _refreshDeviceListViewTimer = new AppTimer((object sender, ElapsedEventArgs e) => { RefreshDeviceListView?.Invoke(sender, EventArgs.Empty); }, 2000); _refreshDeviceListViewTimer.Start(); }
private static void StartMinerStatsCheckTimer() { if (_minerStatsCheck?.IsActive ?? false) { return; } _minerStatsCheck = new AppTimer(async(object sender, ElapsedEventArgs e) => { await MiningManager.MinerStatsCheck(); }, ConfigManager.GeneralConfig.MinerAPIQueryInterval * 1000); _minerStatsCheck.Start(); }
private static void StartPreventSleepTimer() { if (_preventSleepTimer?.IsActive ?? false) { return; } // sleep time setting is minimal 1 minute _preventSleepTimer = new AppTimer((s, e) => { PInvoke.PInvokeHelpers.PreventSleep(); }, 20 * 1000);// leave this interval, it works _preventSleepTimer.Start(); }
void PostInitialize(params MuiAppService[] serviso) { foreach (var windex in WidgetsIndexed) { Widgets[windex].Initialize(this, null); } Services.AddRange(serviso); MuiAppService.RegisterAll(this); MouseWheel += OnMouseWheel; AppTimer.Tick += AppTimer_Tick; AppTimer.Start(); }
private static void StartComputeDevicesCheckTimer() { if (_cudaDeviceCheckerTimer?.IsActive ?? false) { return; } _cudaDeviceCheckerTimer = new AppTimer(async(object sender, ElapsedEventArgs e) => { if (!GlobalDeviceSettings.Instance.CheckForMissingGPUs) { return; } // this function checks if count of CUDA devices is same as it was on application start, reason for that is // because of some reason (especially when algo switching occure) CUDA devices are dissapiring from system // creating tons of problems e.g. miners stop mining, lower rig hashrate etc. var hasMissingGPUs = await DeviceDetection.CheckIfMissingGPUs(); if (!hasMissingGPUs) { return; } if (GlobalDeviceSettings.Instance.RestartMachineOnLostGPU) { Logger.Info("ApplicationStateManager.Timers", $"Detected missing GPUs will execute 'OnGPUsLost.bat'"); try { var onGpusLost = new ProcessStartInfo { FileName = Paths.RootPath("OnGPUsLost.bat"), WindowStyle = ProcessWindowStyle.Minimized }; using (var p = Process.Start(onGpusLost)) { //p.WaitForExit(10 * 1000); } } catch (Exception ex) { Logger.Error("ApplicationStateManager.Timers", $"OnGPUsMismatch.bat error: {ex.Message}"); } } else { Logger.Info("ApplicationStateManager.Timers", $"Detected missing GPUs"); AvailableNotifications.CreateMissingGPUsInfo(); } }, 5 * 60 * 1000); // check every 5 minutes _cudaDeviceCheckerTimer.Start(); }
public static void StartInternetCheckTimer() { if (ConfigManager.GeneralConfig.IdleWhenNoInternetAccess) { OnInternetCheck?.Invoke(null, Helpers.IsConnectedToInternet()); } if (_internetCheckTimer?.IsActive ?? false) { return; } _internetCheckTimer = new AppTimer((object sender, ElapsedEventArgs e) => { if (ConfigManager.GeneralConfig.IdleWhenNoInternetAccess) { OnInternetCheck?.Invoke(null, Helpers.IsConnectedToInternet()); } }, 1000 * 60); _internetCheckTimer.Start(); }
private static void StartComputeDevicesCheckTimer() { if (_cudaDeviceCheckerTimer?.IsActive ?? false) { return; } _cudaDeviceCheckerTimer = new AppTimer(async(object sender, ElapsedEventArgs e) => { if (!ConfigManager.GeneralConfig.RunScriptOnCUDA_GPU_Lost) { return; } // this function checks if count of CUDA devices is same as it was on application start, reason for that is // because of some reason (especially when algo switching occure) CUDA devices are dissapiring from system // creating tons of problems e.g. miners stop mining, lower rig hashrate etc. var nvidiaCount = await DeviceDetection.CUDADevicesNumCheck(); var isDevicesCountMistmatch = nvidiaCount != AvailableDevices.AvailNVGpus; if (isDevicesCountMistmatch) { try { var onGpusLost = new ProcessStartInfo { FileName = Paths.RootPath("OnGPUsLost.bat"), WindowStyle = ProcessWindowStyle.Minimized }; using (var p = Process.Start(onGpusLost)) { //p.WaitForExit(10 * 1000); } } catch (Exception ex) { Logger.Error("ApplicationStateManager.Timers", $"OnGPUsMismatch.bat error: {ex.Message}"); } } }, 60 * 1000); _cudaDeviceCheckerTimer.Start(); }
public override void Enter() { this.resourceAssets.LoadResources(Constants.FONT_NAMES, Constants.TEXTURES_NAMES, Constants.SOUND_NAMES); cAnimationAssets.LoadAnimations(this.resourceAssets); BulletBreed.Init(this.resourceAssets); PickupEffects.InitPickupEffects(this.resourceAssets); camera = new Camera(new View(new Vector2f(appControllerRef.WindowSize.X / 2.0f, appControllerRef.WindowSize.Y / 2.0f), appControllerRef.WindowSize)); camera.Zoom = 0.6f; // 0.6f; appControllerRef.MainWindow.SetView(camera.View); /* * Vector2f viewSize = new Vector2f(appController.MainWindow.Size.X, appController.MainWindow.Size.Y); * * m_View.Size = new Vector2f(viewSize.X, viewSize.Y); * m_View.Center = new Vector2f(viewSize.X / 2.0f, viewSize.Y / 2.0f); * m_View.Viewport = new FloatRect(0.0f, 0.0f, 1.0f, 1.0f); * m_View.Zoom(0.6f); //0.6f * * viewRect = new AABB(); * viewRect.SetDims(m_View.Size); */ worldEnvironment = new cEnvironment(); // Constants.LIGHTMAP_COLOR lightMap = new cLightSystem(Constants.LIGHTMAP_COLOR, this.resourceAssets); //((uint)m_World.WorldBounds.dims.X, (uint)m_World.WorldBounds.dims.Y, Constants.LIGHTMAP_COLOR); gameWorld = new cWorld(this, appControllerRef.MainWindow.Size); gameWorld.InitLevel(); //lightMap.Create((uint)m_World.WorldBounds.dims.X, (uint)m_World.WorldBounds.dims.Y); lightMap.Create(appControllerRef.MainWindow.Size.X, appControllerRef.MainWindow.Size.Y); lightMap.loadLightsFromTmxMap(gameWorld.CurrentLevel.GetTmxMap()); this.staticTexture = new RenderTexture((uint)gameWorld.WorldBounds.dims.X, (uint)gameWorld.WorldBounds.dims.Y); this.staticTexture.SetActive(true); this.staticTexture.Clear(new Color(0, 0, 0, 0)); //this.staticTexture.SetView(m_View); Vector2f playerStart = new Vector2f(gameWorld.LevelStartRegion.center.X, gameWorld.LevelStartRegion.rightBottom.Y); playerStart.X -= Constants.CHAR_FRAME_WIDTH / 2.0f; playerStart.Y -= Constants.CHAR_FRAME_HEIGHT; player = new cPlayer(this, playerStart); entityPool = new GameObjectGrid(this, gameWorld.WorldBounds.dims, player); entityPool.InitLevelEntites(World.CurrentLevel); //vizekhez adunk fényt /* * List<cWaterBlock> waterBlocks = m_World.GetWaterBlocks(); * * foreach (cWaterBlock wb in waterBlocks) * { * cLight waterLight = new cLight(); //víz blokkokhoz adunk fényt, mert jól néz ki * waterLight.Pos = new Vector2f(wb.Area.center.X, wb.Area.topLeft.Y+Constants.TILE_SIZE/2.0f); * waterLight.Radius = (wb.Area.dims.X + wb.Area.dims.Y) * 0.8f; * waterLight.Bleed = 0.00001f; // 0.00001f; * waterLight.LinearizeFactor = 0.95f; * waterLight.Color = new Color(41,174,232); // 96,156,164 * lightMap.AddStaticLight(waterLight); * } * * //háttér, környezeti tárgyak megjelenítése * worldEnvironment.SetWaterBlocks(waterBlocks); */ this.particleManager = new cParticleManager(this); this.effectSystem = new EffectSystem(); // lightMap.renderStaticLightsToTexture(); gameActions = new Queue <Action>(50); Listener.GlobalVolume = 80; Listener.Direction = new Vector3f(1.0f, 0.0f, 0.0f); ShakeScreen.Init(camera.ActualPosition); //Pálya idő start levelTimer.Start(); }
private void MusicInitialize(string path) { if (WaveOutEvent != null) { WaveOutEvent.Dispose(); } if (AudioFileReader != null) { AudioFileReader.Dispose(); } try { AudioFileReader = new AudioFileReader(path); WaveOutEvent = new WaveOutEvent(); WaveOutEvent.Init(AudioFileReader); WaveOutEvent.Play(); if (!AppTimer.Enabled) { AppTimer.Start(); } MusicState = MusicState.Play; ButtonPlayPause.BackgroundImage = Properties.Resources.Pause; PlayAndPauseToolStripMenuItem.Text = "Pause"; PlaybackBarControl.Max = Convert.ToInt32(ConvertFrom.TimeToSeconds(AudioFileReader.TotalTime)); AudioFileReader.Volume = TrackBarVolumeState.Value / 10f; // This condition is related to the (Exception) Code Part // The Path Variable will be changed to the CurrentPlayingMusic, for get the original audio meatdata if (IsFileGenerateException) { path = Music[CurrentPlayingMusicIndex]; } // Change the Label Text to the Music Total Time // Change the PictureBox BackgroundImage to the Music Cover LabelMusicEndTime.Text = AudioFileReader.TotalTime.ToString(@"mm\:ss"); PictureBoxMusicCover.BackgroundImage = TagFile.GetCover(path); // Change the Form Title to the Music Title + Artist this.Text = TagFile.GetArtists(path) + " - " + TagFile.GetTitle(path); // Change the Current MusicPanel BackgroundColor, and reset the others foreach (MusicPanel musicPanel in FlowLayoutPanelMusic.Controls) { if (musicPanel.MusicPath == path) { musicPanel.BackColor = Color.FromArgb(28, 28, 28); } else { musicPanel.BackColor = Color.Transparent; } } // Reset the "IsFileGenerateException" value to false IsFileGenerateException = false; } catch { try { // If Audio File GenerateException, Convert it to 'wav' and save it // on a Temp File, so we can play it later AudioFileReader = null; using (var reader = new MediaFoundationReader(Music[CurrentPlayingMusicIndex])) { if (!Directory.Exists("TempFiles/")) { Directory.CreateDirectory("TempFiles/"); } // Save the 'wav' audio on the Temp File WaveFileWriter.CreateWaveFile("TempFiles/temp.wav", reader); } // Change the "IsFileGenerateException" value to true, because the File is Generate Exception IsFileGenerateException = true; // Try to play the Temp File, if isn't played alert a message to the user MusicInitialize("TempFiles/temp.wav"); } catch (Exception Ex) { MessageBox.Show("This song is hard for us to play it for you, Please play another one." + Environment.NewLine + "(" + Ex.Message + ")", "We are sorry!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/* * public static GlobalClock Instance * { * get * { * return instance; * } * } */ public static void Start() { timer.Start(); }