public static void Update(IntPtr windowPtr) { MousePosition = WinApi.GetCursorPosition(windowPtr); try { RegisteredKeys.ForEach(key => { var keyState = GetKeyState(key); if (keyState == false && Keys[key]) { ReleaseKey?.Invoke(null, key); } Keys[key] = keyState; }); } catch (Exception e) { DebugWindow.LogMsg($"{nameof(Input)} {e}"); } }
public void LogMessage(string msg, float time = 1f) { DebugWindow.LogMsg(msg, time, Color.GreenYellow); }
public void LogMessage(string msg, float time, Color clr) { DebugWindow.LogMsg(msg, time, clr); }
public void LogMsg(string msg) { DebugWindow.LogMsg(msg); }
public void Process(object o) { if (threads == null) { return; } if (Interlocked.CompareExchange(ref _lock, 1, 0) == 1) { return; } if (ProcessWorking) { DebugWindow.LogMsg($"WTF {_objectInitWork.GetType()}"); } _objectInitWork = o; ProcessWorking = true; spinWait.Reset(); while (Jobs.TryDequeue(out var j)) { processJobs.Enqueue(j); } if (ThreadsCount > 1) { while (processJobs.Count > 0) { if (!FreeThreads.IsEmpty) { FreeThreads.TryDequeue(out var freeThread); var job = processJobs.Dequeue(); if (!freeThread.AddJob(job)) { processJobs.Enqueue(job); } else { if (freeThread.Free) { FreeThreads.Enqueue(freeThread); } } } else { spinWait.SpinOnce(); var allThreadsBusy = true; for (var i = 0; i < threads.Length; i++) { var th = threads[i]; if (th.Free) { allThreadsBusy = false; FreeThreads.Enqueue(th); } } if (allThreadsBusy) { for (var i = 0; i < threads.Length; i++) { var th = threads[i]; var thWorkingTime = th.WorkingTime; if (thWorkingTime > CriticalWorkTimeMs) { DebugWindow.LogMsg( $"Repair thread #{th.Number} with Job1: {th.Job.Name} (C: {th.Job.IsCompleted} F: {th.Job.IsFailed}) && Job2:{th.SecondJob.Name} (C: {th.SecondJob.IsCompleted} F: {th.SecondJob.IsFailed}) Time: {thWorkingTime} > {thWorkingTime >= CriticalWorkTimeMs}", 5); th.Abort(); BrokenThreads.Add(th); var newThread = new ThreadUnit($"Repair critical time {th.Number}", th.Number); threads[th.Number] = newThread; FreeThreads.Enqueue(newThread); Thread.Sleep(5); FailedThreadsCount++; break; } } } } } } else { var threadUnit = threads[0]; while (processJobs.Count > 0) { if (threadUnit.Free) { var job = processJobs.Dequeue(); threadUnit.AddJob(job); } else { spinWait.SpinOnce(); var threadUnitWorkingTime = threadUnit.WorkingTime; if (threadUnitWorkingTime > CriticalWorkTimeMs) { DebugWindow.LogMsg( $"Repair thread #{threadUnit.Number} withreadUnit Job1: {threadUnit.Job.Name} (C: {threadUnit.Job.IsCompleted} F: {threadUnit.Job.IsFailed}) && Job2:{threadUnit.SecondJob.Name} (C: {threadUnit.SecondJob.IsCompleted} F: {threadUnit.SecondJob.IsFailed}) Time: {threadUnitWorkingTime} > {threadUnitWorkingTime >= CriticalWorkTimeMs}", 5); threadUnit.Abort(); BrokenThreads.Add(threadUnit); threadUnit = new ThreadUnit($"Repair critical time {threadUnit.Number}", threadUnit.Number); Thread.Sleep(5); FailedThreadsCount++; } } } } if (BrokenThreads.Count > 0) { var criticalWorkTimeMs = CriticalWorkTimeMs * 2; for (var index = 0; index < BrokenThreads.Count; index++) { var brokenThread = BrokenThreads[index]; if (brokenThread == null) { continue; } if (brokenThread.WorkingTime > criticalWorkTimeMs) { brokenThread.ForceAbort(); BrokenThreads[index] = null; } } if (BrokenThreads.AllF(x => x == null)) { BrokenThreads.Clear(); } } Interlocked.CompareExchange(ref _lock, 0, 1); ProcessWorking = false; }