我是C#的新手,我正试着这样做:
myList = list of 1000+ string values;
1.StartNewThreads(50); //50 is the numbers of new threads
2.DoSth1(next value from myList);
3.DoSth2();
4. var value = {
ShowNewImageForm(); //show only if not another ImageForm is displayed if another is show - wait
WaitUntilUserPressEnterInTextBox();
ReturnValueFormTextbox();
}
5.DoSth3();
6.StartNewThread();
现在我有:
foreach(String s in myList ) {
DoSth1(s);
DoSth2();
DoSth3();
}
现在我正在寻找点1,3,6的想法你能建议我如何解决这个问题吗?
答案 0 :(得分:0)
对于你的第二个问题: 只需在子表单的构造函数中传递父表单/所有者表单,并使用该引用传递/设置返回值,或者(更优雅)定义一旦用户按下返回键然后在子表单上触发的事件,然后添加一个父表单中的事件处理程序。
答案 1 :(得分:0)
要启动一些线程,可以使用Thread []
public static void StartThreads(int n)
{
System.Threading.Thread[] threads = new System.Threading.Thread[n];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new System.Threading.Thread(new System.Threading.ThreadStart(DoThread));
}
}
public static void DoThread()
{
//do some here
}
在第二种形式中,您可以定义此处理程序:
public static void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox myText = (TextBox)sender;
//your code here...
}
}
然后以第一种形式:
textBox1.KeyDown += new KeyEventHandler(Form2.textBox1_KeyDown);