如何指定要使用的线程数量?

编程入门 行业动态 更新时间:2024-10-24 12:24:01
本文介绍了如何指定要使用的线程数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我希望用户能够指定我的程序应该使用多少线程,然后我尝试使用maxdegree并行,但它只限制了我的程序可以使用的线程数量。这是我的代码请帮助:

So I want user to be able to specify how many threads my program should use,before I tried with maxdegree of parallelism but It only limited the amount of threads my program could use.Here is my code pls help:

class Program { static Regex idcheck = new Regex(@"id"":""(.+?)"","); static Regex Migrationcheck = new Regex(@"legacy"":(.+?)}"); private static String _outputFileUnmigrated = "Unmigrated.txt"; private static String _outputFileMigrated = "Migrated.txt"; private static String _outputFileAvailable = "Available.txt"; private static String _outputValidationLog = "ValidationLog.txt"; private static String _outputUnmigratedGood = "UnmigratedGood.txt"; private static String _outputUnmigratedBad = "UnmigratedBad.txt"; static void Main(string[] args) { Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + 0 + " | Good:" + 0; [REDACTED] Console.Write("Threads : "); int threads = int.Parse(Console.ReadLine()); UserInput: Console.WriteLine("Please specify the type of list."); Console.WriteLine("Type 1 for user"); Console.WriteLine("Type 2 for user:pass"); Console.WriteLine("Type 3 for user:hash:pass"); Console.WriteLine(""); int ListType = int.Parse(Console.ReadLine()); if(ListType > 3) { goto UserInput; } Console.WriteLine("If you want only legacy type 0,if you want legacy+unmigrated type 1"); int CheckingMode = int.Parse(Console.ReadLine()); var lines = File.ReadLines("List.txt"); var UnmigratedNumber = 0; var MigratedNumber = 0; var AvailableNumber = 0; using (StreamWriter UnmigratedGoodWriter = File.AppendText(_outputUnmigratedGood)) { using (StreamWriter UnmigratedBadWriter = File.AppendText(_outputUnmigratedBad)) { using (StreamWriter AvailableWriter = File.AppendText(_outputFileAvailable)) { using (StreamWriter UnmigratedWriter = File.AppendText(_outputFileUnmigrated)) { using (StreamWriter MigratedWriter = File.AppendText(_outputFileMigrated)) { Parallel.ForEach(lines, name => { string localPath = null; if (ListType == 1) { localPath = name; } if (ListType == 2) { string pattern = @"\:.*"; string replacement = ""; localPath = Regex.Replace(name, pattern, replacement, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); } if (ListType == 3) { string pattern1 = @":.*?:"; string replacement1 = ":"; string RemoveHash = Regex.Replace(name, pattern1, replacement1, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); string pattern2 = @"\:.*"; string replacement2 = ""; localPath = Regex.Replace(RemoveHash, pattern2, replacement2, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); } // foreach (var line in lines) var porxies = File.ReadLines("Proxies.txt"); args = new[] { "api.mojang/users/profiles/minecraft/" + localPath }; using (var client1 = new WebClient()) { var content = string.Empty; foreach (var proxy in porxies) { WebProxy wp = new WebProxy(proxy.ToString()); client1.Proxy = wp; try { content = ScrubContent(client1.DownloadString(args[0])); break; } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("BAD PROXY {0}", proxy); Console.WriteLine(ex.Message); } } try { var idchecked = idcheck.Matches(content).Cast<Match>().Single().Groups[1]; args = new[] { "sessionserver.mojang/session/minecraft/profile/" + idchecked }; } catch (InvalidOperationException ex) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Available name " + localPath); AvailableWriter.WriteLine(name); AvailableNumber++; } using (var client2 = new WebClient()) { var content1 = string.Empty; foreach (var proxy in porxies) { WebProxy wp = new WebProxy(proxy.ToString()); client2.Proxy = wp; try { content1 = ScrubContent(client2.DownloadString(args[0])); break; } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("BAD PROXY {0}", proxy); } } try { var migrationchecked = Migrationcheck.Matches(content1).Cast<Match>().Single().Groups[1]; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("UNMIGRATED " + localPath); UnmigratedWriter.WriteLine(name); UnmigratedNumber++; Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber; if (ListType == 2 && CheckingMode == 1) { string password = null; string pattern = @".+(\:)"; string replacement = ""; password = Regex.Replace(name, pattern, replacement, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); var httpWebRequest = (HttpWebRequest)WebRequest.Create("authserver.mojang/authenticate"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{" + "\r\n" + "\"agent\": {" + "\r\n" + " \"name\": \"Minecraft\"," + "\r\n" + " \"version\": 1" + "\r\n" + "}," + "\r\n" + "\"username\": \"" + localPath + "\"," + "\r\n" + "\"password\": \"" + password + "\"" + "\r\n" + "}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } try { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); var streamReader = new StreamReader(httpResponse.GetResponseStream()); var result = streamReader.ReadToEnd(); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("UNMIGRATED " + localPath + " is good"); UnmigratedGoodWriter.WriteLine(name); } catch (InvalidOperationException ex) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("UNMIGRATED " + localPath + " is bad"); UnmigratedBadWriter.WriteLine(name); } } if (ListType == 3 && CheckingMode == 1) { string pattern1 = @":.*?:"; string replacement1 = ":"; string RemoveHash = Regex.Replace(name, pattern1, replacement1, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); string password = null; string pattern = @".+(\:)"; string replacement = ""; password = Regex.Replace(RemoveHash , pattern, replacement, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(0.5)); var httpWebRequest = (HttpWebRequest)WebRequest.Create("authserver.mojang/authenticate"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{" + "\r\n" + "\"agent\": {" + "\r\n" + " \"name\": \"Minecraft\"," + "\r\n" + " \"version\": 1" + "\r\n" + "}," + "\r\n" + "\"username\": \"" + localPath + "\"," + "\r\n" + "\"password\": \"" + password + "\"" + "\r\n" + "}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } try { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); var streamReader = new StreamReader(httpResponse.GetResponseStream()); var result = streamReader.ReadToEnd(); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("UNMIGRATED " + localPath + " is good"); UnmigratedGoodWriter.WriteLine(name); } catch (InvalidOperationException ex) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("UNMIGRATED " + localPath + " is bad"); UnmigratedBadWriter.WriteLine(name); } } } catch (InvalidOperationException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("MIGRATED " + localPath); MigratedWriter.WriteLine(name); MigratedNumber++; Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber; } } } }); } } } } } Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("====================Results===================="); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Checked: {0} accounts", UnmigratedNumber + MigratedNumber); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Unmigrated: {0} accounts", UnmigratedNumber); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Migrated: {0} accounts", MigratedNumber); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Available: {0} names", AvailableNumber); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("====================Results===================="); Console.ReadLine(); } static string ScrubContent(string content) { return new string(content.Where(c => c != '\n').ToArray()); } }

推荐答案

您好,

在代码中,您几乎无法弄清楚自己在做什么。

In code you provide almost impossible to figure out what you doing.

对于任务:实施TThreadManager和用它来管理线程。

For the task: implement TThreadManager and use it to manage thread's.

更多推荐

如何指定要使用的线程数量?

本文发布于:2023-11-05 09:27:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   要使   数量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!