I have a problem regarding the thread I have created. When I start the Thread, the CPU usage becomes higher and makes the server slow. I want to abort this process and re-run it. I am using a ClrThread to find the Method inside the processes using the namespaces. How can I do the Thread.Abort()
in ClrThread?
this is my code.
int _threadCounter = 0; Thread reminderThread = new Thread(CreateObject); string startOfThisNamespace = this.GetType().Namespace.ToString().Split('.')[0]; using (DataTarget target = DataTarget.AttachToProcess(System.Diagnostics.Process.GetCurrentProcess().Id, false)) { ClrRuntime runtime = target.ClrVersions.First().CreateRuntime(); foreach(ClrThread _thread in runtime.Threads.ToList()) { _threadCounter += 1; IEnumerable<ClrStackFrame> _stackFrames = _thread.EnumerateStackTrace(); List<ClrStackFrame> _stackRelatedToUs = _stackFrames .Where(o => o.Method != null && o.Method.ToString().StartsWith(startOfThisNamespace)).ToList(); if (_stackRelatedToUs.Count > 0) { foreach (var s in _stackRelatedToUs) { string _methodName = s.Method.Name; if (_methodName == "CreateObject") { if (_thread.IsAlive) { } } reminderThread.Start(); } } else { if (_threadCounter == runtime.Threads.Count()) { reminderThread.Start(); } } } }
Thank you and Regards.
https://stackoverflow.com/questions/66913942/how-to-abort-the-clrthread April 02, 2021 at 11:06AM
没有评论:
发表评论