如果可能的话,在不使用大量CPU和RAM的情况下提取数据的更好方法是什么?我正在使用SwiftApi Bukkit插件用于使用Apache Thrift的Minecraft。基本上我正在尝试制作一个远程控制台。它目前的工作原理我想要它但有时它使用了很多我的CPU,有时RAM。所以我的问题是,使用这种方法做得更好,资源更少?
private void getConsole2(Object state)
{
try
{
String authString = GetSHA256String("***************");
TSocket socket = new TSocket("******", 21111);
socket.Open();
TBinaryProtocol protocol = new TBinaryProtocol(new TFramedTransport(socket));
SwiftApi.Client client = new SwiftApi.Client(protocol);
List<ConsoleLine> Console = client.getConsoleMessages(authString, (int)t.TotalSeconds);
foreach (ConsoleLine c in Console)
{
//Filtering out some junk
String line = Regex.Replace(c.ToString(), "[^\x0d\x0a\x20-\x7e\t]", "");
line = line.Replace(",Level", "").Replace("[m", "").Replace("[0;33;22m", "").Replace("[0;37;1m", "").Replace("[0;31;1m", "").Replace("[0;37;22m", "").Replace("[0;36;1m", "").Replace("[0;34;22m", "").Replace("[0;36;22m", "").Replace("[0;31;22m", "").Replace("[0;35;1m", "").Replace("[0;30;1m", "").Replace("[0;32;1m", "").Replace("[0;32;22m", "").Replace("[0;35;22m", "").Replace("[0;34;1m", "").Replace("[0;30;22m", "").Replace("[0;33;1m", "").Replace("[3m", "");
string[] s = line.Split(':');
string part1 = s[1].Replace(",Message", "").Replace(" ", "");
richTextBox2.Invoke(new Action(() =>
{
if (!richTextBox2.Text.Contains(ConvertUnixTimeStamp(part1) + " [" + s.Last().Replace(" ", "").Replace(")", "") + "] " + s[2] + s[3].Replace(s.Last(), "")))
{
if (s.Last().Replace(" ", "").Replace(")", "").Equals("SEVERE"))
{
richTextBox2.Select(richTextBox2.TextLength, 0);
richTextBox2.SelectionColor = Color.Red;
richTextBox2.AppendText(System.Environment.NewLine + ConvertUnixTimeStamp(part1) + " [" + s.Last().Replace(" ", "").Replace(")", "") + "] " + s[2] + s[3].Replace(s.Last(), ""));
if (checkBox2.Checked == true) richTextBox2.ScrollToCaret();
}
else if (s.Last().Replace(" ", "").Replace(")", "").Equals("WARNING"))
{
richTextBox2.Select(richTextBox2.TextLength, 0);
richTextBox2.SelectionColor = Color.Orange;
richTextBox2.AppendText(System.Environment.NewLine + ConvertUnixTimeStamp(part1) + " [" + s.Last().Replace(" ", "").Replace(")", "") + "] " + s[2] + s[3].Replace(s.Last(), ""));
if (checkBox2.Checked == true) richTextBox2.ScrollToCaret();
}
else
{
richTextBox2.Select(richTextBox2.TextLength, 0);
richTextBox2.SelectionColor = Color.FromArgb(205, 205, 205);
richTextBox2.AppendText(System.Environment.NewLine + ConvertUnixTimeStamp(part1) + " [" + s.Last().Replace(" ", "").Replace(")", "") + "] " + s[2] + s[3].Replace(s.Last(), ""));
if (checkBox2.Checked == true) richTextBox2.ScrollToCaret();
}
}
}));
}
socket.Close();
Thread.Sleep(500);
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(getConsole2));
}