|
|
|
C# WinApp อยากทราบว่า ถ้าจะนำ string หรือ ข้อความ มาใช้เป็นโค้ดแล้ว รัน ต้องเขียนโค้ดยังไงครับ |
|
|
|
|
|
|
|
Code (C#)
Type thisType = this.GetType();
MethodInfo theMethod = thisType.GetMethod(TheCommandString);
theMethod.Invoke(this, userParameters);
ใช่ตัวนี้หรือเปล่าครับ
|
|
|
|
|
Date :
2015-11-19 15:03:22 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คิดว่าไม่สามารถจะสั่งรันได้จากการอ่านนะครับ
แต่สามารถเขียนโปรแกรม อ่าน Text File แล้วค่อยรัน อันนี้ได้ครับ
ประมาณว่า Text File มีคำว่า
TOR@Chemistry 5555
string[] lines = System.IO.File.ReadAllLines(@"D:\TOR.txt");
string str;
str = lines[0];
MessageBox.Show(str);
ประมาณนี้ครับ
|
|
|
|
|
Date :
2015-11-19 15:06:41 |
By :
บัญดิษฐ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือผมเขียนโค้ดสำหรับ รันโค้ดแบบนี้ครับ
Code (C#)
void SetVoid()
{
string str = "str = ";
string s = " ";
int num = 3;
s += "void SetData" + num + "()\n { \n count += (int)Math.Pow(Program.symbol.Length," + num + "); \n";
s += "progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; })); \n string str" + num + " = string.Empty; \n";
str = "str" + num + " = ";
for (int i = 1; i < num + 1; i++)
{
s += "foreach (string s" + i + " in Program.symbol){\n";
str += ((str == "str" + num + " = ") ? " s" + i : "+ s" + i);
}
s += "\n try { \n" + str + "; \n Program.Insert(" + Convert.ToChar(34) + num + Convert.ToChar(34) + ", str" + num + "); \n num++; ";
s += "\n this.Invoke(new Action(() => { this.Text = str" + num + "; })); \n double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter; \n double strt = (double)((count - num) * t / num);";
s += "\n str = str" + num + "; new System.Threading.Thread(SetDisplay).Start();";
s += "\n if (num <= progressBar1.Maximum){ \n this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));\n} \n } \n catch { };\n";
for (int i = 1; i < num + 1; i++)
{
s += "}";
}
s += "\n this.Invoke(new Action(() => { this.Text = " + Convert.ToChar(34) + "Complete...." + Convert.ToChar(34) + "; })); \n}";
richTextBox1.Text +="\n \n" + s;
}
จากโค้ดด้านบนพอรันแล้ว จะได้
Code (C#)
void SetData3()
{
count += (int)Math.Pow(Program.symbol.Length, 3);
progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
string str3 = string.Empty;
foreach (string s1 in Program.symbol)
{
foreach (string s2 in Program.symbol)
{
foreach (string s3 in Program.symbol)
{
try
{
str3 = s1 + s2 + s3;
Program.Insert("3", str3);
num++;
this.Invoke(new Action(() => { this.Text = str3; }));
double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
double strt = (double)((count - num) * t / num);
str = str3; new System.Threading.Thread(SetDisplay).Start();
if (num <= progressBar1.Maximum)
{
this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
}
}
catch { };
}
}
}
this.Invoke(new Action(() => { this.Text = "Complete...."; }));
}
แต่ผมคิดว่ามันน่าจะมีทางที่ สร้างเสร็จก็รัน SetData3() ได้เลย แบบนี้ครับ
|
|
|
|
|
Date :
2015-11-19 15:13:48 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555+++ ผมนี้หลงประเด็นไปเลย งั้นลองค้นหาดูเรื่อง Compiling C# Code at Runtime ดูนะครับ
|
|
|
|
|
Date :
2015-11-19 15:28:27 |
By :
บัญดิษฐ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลองหัดใช้ตาม
http://www.codeproject.com/Tips/715891/Compiling-Csharp-Code-at-Runtime
อยู่ครับ
ที่เหลือก็ต้องลองเอามาปรับใช้ดู
ขอถามอีกอย่างครับ
Code (C#)
public static string[] symbol = new string[]{"!","%","&","-",".","/",@"\","_","0","1","2","3","4","5","6","7","8","9","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
void SetData10()
{
count += (int)Math.Pow(Program.symbol.Length, 10);
progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
string str10 = string.Empty;
foreach (string s1 in Program.symbol)
{
foreach (string s2 in Program.symbol)
{
foreach (string s3 in Program.symbol)
{
foreach (string s4 in Program.symbol)
{
foreach (string s5 in Program.symbol)
{
foreach (string s6 in Program.symbol)
{
foreach (string s7 in Program.symbol)
{
foreach (string s8 in Program.symbol)
{
foreach (string s9 in Program.symbol)
{
foreach (string s10 in Program.symbol)
{
try
{
str10 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
Program.Insert("10", str10);
num++;
this.Invoke(new Action(() => { this.Text = str10; }));
double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
double strt = (double)((count - num) * t / num);
str = str10; new System.Threading.Thread(SetDisplay).Start();
if (num <= progressBar1.Maximum)
{
this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
}
}
catch { }; System.Threading.Thread.Sleep(100);
}
}
}
}
}
}
}
}
}
}
this.Invoke(new Action(() => { this.Text = "Complete...."; }));
}
จากโค๊ดนี้ถ้าใช้ Thread เดียวทำงานมันช้ามากครับ
ถ้าจะแบ่งออกมาซัก 50 Thread จะแบ่ง for ยังไงครับ
|
|
|
|
|
Date :
2015-11-19 16:43:51 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดัน ๆๆๆ
ถ้าจะแบ่งออกมาซัก 50 Thread จะแบ่ง for ยังไงครับ
Code (C#)
public static string[] symbol = new string[]{"!","%","&","-",".","/",@"\","_","0","1","2","3","4","5","6","7","8","9","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
void SetData10()
{
count += (int)Math.Pow(Program.symbol.Length, 10);
progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
string str10 = string.Empty;
foreach (string s1 in Program.symbol)
{
foreach (string s2 in Program.symbol)
{
foreach (string s3 in Program.symbol)
{
foreach (string s4 in Program.symbol)
{
foreach (string s5 in Program.symbol)
{
foreach (string s6 in Program.symbol)
{
foreach (string s7 in Program.symbol)
{
foreach (string s8 in Program.symbol)
{
foreach (string s9 in Program.symbol)
{
foreach (string s10 in Program.symbol)
{
try
{
str10 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
Program.Insert("10", str10);
num++;
this.Invoke(new Action(() => { this.Text = str10; }));
double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
double strt = (double)((count - num) * t / num);
str = str10; new System.Threading.Thread(SetDisplay).Start();
if (num <= progressBar1.Maximum)
{
this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
}
}
catch { }; System.Threading.Thread.Sleep(100);
}
}
}
}
}
}
}
}
}
}
this.Invoke(new Action(() => { this.Text = "Complete...."; }));
}
|
|
|
|
|
Date :
2015-11-23 10:33:37 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|