internal void Add_DbgThread(DbgThreadImpl thread) { Dispatcher.VerifyAccess(); lock (lockObj) threads.Add(thread); ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(thread, added: true)); }
internal void NotifyRuntimesChanged_DbgThread(DbgRuntime runtime) { bool raiseDebuggingChanged; DbgThread[] removedThreads; lock (lockObj) { var newDebugging = CalculateDebugging_NoLock(); raiseDebuggingChanged = !StringArrayEquals(debugging, newDebugging); if (raiseDebuggingChanged) { debugging = newDebugging; } runtime.ThreadsChanged -= DbgRuntime_ThreadsChanged; var threadsList = new List <DbgThread>(); for (int i = threads.Count - 1; i >= 0; i--) { var thread = threads[i]; if (thread.Runtime == runtime) { threadsList.Add(thread); threads.RemoveAt(i); } } removedThreads = threadsList.ToArray(); } if (removedThreads.Length != 0) { ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(removedThreads, added: false)); } if (raiseDebuggingChanged) { OnPropertyChanged(nameof(Debugging)); } if (!(runtime is null)) RuntimesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgRuntime>(runtime, added: false)); }
internal void Remove_DbgThread(DbgThreadImpl thread, DbgEngineMessageFlags messageFlags) { Dispatcher.VerifyAccess(); lock (lockObj) { bool b = threads.Remove(thread); if (!b) { return; } } owner.RemoveThread_DbgThread(this, thread, messageFlags); ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(thread, added: false)); thread.Close(Dispatcher); }
public void Compress(string file, int threadsCount) { var fileBytes = File.ReadAllBytes(file); var inputChunks = ParseBytes(fileBytes, threadsCount); ThreadsChanged?.Invoke(inputChunks.Count); var threads = new List <Task <byte[]> >(); const string extension = ".gz"; var start = DateTime.Now.Ticks; for (var i = 0; i < inputChunks.Count; i++) { var iter = i; threads.Add(new Task <byte[]>(() => { try { using (var mStream = new MemoryStream()) { using (var gZipStream = new GZipStream(mStream, CompressionMode.Compress)) { var lenght = inputChunks[iter].Length / 100; if (lenght < 1) { gZipStream.Write(inputChunks[iter], 0, inputChunks[iter].Length); ProgressValueChanged?.Invoke(iter, 100); } else { for (var j = 0; j < 100; j++) { gZipStream.Write(inputChunks[iter], j * lenght, lenght); ProgressValueChanged?.Invoke(iter); } gZipStream.Write(inputChunks[iter], lenght * 100, inputChunks[iter].Length - lenght * 100); } } return(mStream.ToArray()); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } })); } threads.ForEach(x => x.Start()); WhenCompressThreadsDone(file + extension, threads, start); }
protected override void CloseCore(DbgDispatcher dispatcher) { DbgThread[] removedThreads; DbgModule[] removedModules; DbgAppDomain[] removedAppDomains; DbgObject[] objsToClose; lock (lockObj) { removedThreads = threads.ToArray(); removedModules = modules.ToArray(); removedAppDomains = appDomains.ToArray(); objsToClose = closeOnContinueList.ToArray(); threads.Clear(); modules.Clear(); appDomains.Clear(); closeOnContinueList.Clear(); } currentThread = default; if (removedThreads.Length != 0) { ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(removedThreads, added: false)); } if (removedModules.Length != 0) { ModulesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgModule>(removedModules, added: false)); } if (removedAppDomains.Length != 0) { AppDomainsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgAppDomain>(removedAppDomains, added: false)); } foreach (var obj in objsToClose) { obj.Close(dispatcher); } foreach (var thread in removedThreads) { thread.Close(dispatcher); } foreach (var module in removedModules) { module.Close(dispatcher); } foreach (var appDomain in removedAppDomains) { appDomain.Close(dispatcher); } InternalRuntime.Close(dispatcher); }
void DbgRuntime_ThreadsChanged(object?sender, DbgCollectionChangedEventArgs <DbgThread> e) { lock (lockObj) { if (e.Added) { threads.AddRange(e.Objects); } else { foreach (var thread in e.Objects) { bool b = threads.Remove(thread); Debug.Assert(b); } } } ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(e.Objects, added: e.Added)); }
public void Decompress(string fileName) { var start = DateTime.Now.Ticks; var file = File.ReadAllBytes(fileName); fileName = fileName.Remove(fileName.Length - 3, 3); var chunks = file.SearchBytePattern(gzipHeader); ThreadsChanged?.Invoke(chunks.Count); if (chunks.Count == 0 || chunks[0] != 0) { CompressionDoneEventHandler?.Invoke(true, "File is not an archive, or damaged!"); return; } var threads = new List <Task <byte[]> >(); var offset = 0; try { if (chunks.Count == 1) { DecompressThreadsAdd(threads, 0, file.Length, file); } else { for (int i = 1; i < chunks.Count; i++) { var iter = i; offset = chunks[iter - 1]; DecompressThreadsAdd(threads, offset, chunks[iter] - offset, file); } DecompressThreadsAdd(threads, chunks.LastOrDefault(), file.Length - chunks.LastOrDefault() - 1, file); } threads.ForEach(x => x.Start()); WhenCompressThreadsDone(fileName, threads, start); } catch (Exception ex) { CompressionDoneEventHandler?.Invoke(true, ex.Message); } }
internal void Add_DbgThread(DbgEngine engine, DbgRuntimeImpl runtime, DbgProcessState newState) { bool raiseStateChanged, raiseDebuggingChanged, raiseIsRunningChanged; DbgThread[] addedThreads; lock (lockObj) { engineInfos.Add(new EngineInfo(engine, runtime)); var newDebugging = CalculateDebugging_NoLock(); raiseStateChanged = state != newState; raiseDebuggingChanged = !StringArrayEquals(debugging, newDebugging); state = newState; if (raiseDebuggingChanged) { debugging = newDebugging; } var newIsRunning = CalculateIsRunning_NoLock(); raiseIsRunningChanged = cachedIsRunning != newIsRunning; cachedIsRunning = newIsRunning; addedThreads = runtime.Threads; runtime.ThreadsChanged += DbgRuntime_ThreadsChanged; } RuntimesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgRuntime>(runtime, added: true)); if (addedThreads.Length != 0) { ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(addedThreads, added: true)); } if (raiseStateChanged) { OnPropertyChanged(nameof(State)); } if (raiseIsRunningChanged) { IsRunningChanged?.Invoke(this, EventArgs.Empty); } if (raiseDebuggingChanged) { OnPropertyChanged(nameof(Debugging)); } }
internal void Remove_DbgThread(DbgAppDomainImpl appDomain, DbgEngineMessageFlags messageFlags) { Dispatcher.VerifyAccess(); List <DbgThread>?threadsToRemove = null; List <DbgModule>?modulesToRemove = null; lock (lockObj) { bool b = appDomains.Remove(appDomain); if (!b) { return; } for (int i = threads.Count - 1; i >= 0; i--) { var thread = threads[i]; if (thread.AppDomain == appDomain) { if (threadsToRemove is null) { threadsToRemove = new List <DbgThread>(); } threadsToRemove.Add(thread); threads.RemoveAt(i); } } for (int i = modules.Count - 1; i >= 0; i--) { var module = modules[i]; if (module.AppDomain == appDomain) { if (modulesToRemove is null) { modulesToRemove = new List <DbgModule>(); } modulesToRemove.Add(module); modules.RemoveAt(i); } } } if (threadsToRemove is not null && threadsToRemove.Count != 0) { ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(threadsToRemove, added: false)); } if (modulesToRemove is not null && modulesToRemove.Count != 0) { ModulesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgModule>(modulesToRemove, added: false)); } owner.RemoveAppDomain_DbgThread(this, appDomain, messageFlags); AppDomainsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgAppDomain>(appDomain, added: false)); if (threadsToRemove is not null) { foreach (var thread in threadsToRemove) { thread.Close(Dispatcher); } } if (modulesToRemove is not null) { foreach (var module in modulesToRemove) { module.Close(Dispatcher); } } appDomain.Close(Dispatcher); }