14 个解决方案
#1
#2
private void fun()
{
for (int i = 0; i < 100; i++)
{
}
Invoke(new MethodInvoker(delegate() { MessageBox.Show("完成"); }));
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
}
#3
private void fun()
{
for (int i = 0; i < 100; i++)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
MessageBox.Show("完成");
}
这种情况怎样让它在执行完t线程后在执行messagebox呢
{
for (int i = 0; i < 100; i++)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
MessageBox.Show("完成");
}
这种情况怎样让它在执行完t线程后在执行messagebox呢
#4
Thread t = new Thread(delegate() {fun();});
t.Start();
if(t.ThreadState==ThreadState.Stopped)
MessageBox.Show("完成");
t.Start();
if(t.ThreadState==ThreadState.Stopped)
MessageBox.Show("完成");
#5
invoke 2楼。
#6
这种做法有什么意义呢?
为什么不直接fun();然后msg ?
为什么不直接fun();然后msg ?
#7
或者干脆你用一部调用,别用现成了
#8
异步调用
#9
也可以把MessageBox.Show("完成"); 放到另一个线程里面去啊,两个线程可以用线程锁来进行控制的,当运行A线程后,再去运行后面的线程的,
。。。
lock (qqMain.myUsering)
{
readInfo = myPort.ReadInfo();
}
。。。
。。。
lock (qqMain.myUsering)
{
readInfo = myPort.ReadInfo();
}
。。。
#10
Thread t = new Thread(delegate() {fun();});
t.Start();
while(t.ThreadState!=ThreadState.Stopped){}
MessageBox.Show("完成");
t.Start();
while(t.ThreadState!=ThreadState.Stopped){}
MessageBox.Show("完成");
#11
public Form1()
{
InitializeComponent();
doSomeThred();
}
/// <summary>
/// 异步线程
/// </summary>
private void doSomeThred()
{
doThreadSynch();
}
private void DoSomeThing()
{
try
{
this.richTextBox1.Text += "dobegin\r\n";
Thread.Sleep(2000);
this.richTextBox1.Text += "doend\r\n";
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
private void CallBackMethod(IAsyncResult ar)
{
doDelegate d = (doDelegate)ar.AsyncState;
this.richTextBox1.Text += "Threadend\r\n";
MessageBox.Show("调用完毕");
d.EndInvoke(ar);
}
private delegate void doDelegate();
private void doThreadSynch()
{
doDelegate dlg = new doDelegate(DoSomeThing);
AsyncCallback acb = new AsyncCallback(CallBackMethod);
this.richTextBox1.Text += "ThreadBegin\r\n";
IAsyncResult iar = dlg.BeginInvoke(acb, dlg);
}
#12
找一个msdn看看关于System.Threading.WaitHandle的例子
#13
异步回调或使用线程同步
或则在MessageBox前用Thread.join 好像可以
或则在MessageBox前用Thread.join 好像可以
#14
多看看,多学习学习
#1
#2
private void fun()
{
for (int i = 0; i < 100; i++)
{
}
Invoke(new MethodInvoker(delegate() { MessageBox.Show("完成"); }));
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
}
#3
private void fun()
{
for (int i = 0; i < 100; i++)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
MessageBox.Show("完成");
}
这种情况怎样让它在执行完t线程后在执行messagebox呢
{
for (int i = 0; i < 100; i++)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(delegate() { fun(); });
t.Start();
MessageBox.Show("完成");
}
这种情况怎样让它在执行完t线程后在执行messagebox呢
#4
Thread t = new Thread(delegate() {fun();});
t.Start();
if(t.ThreadState==ThreadState.Stopped)
MessageBox.Show("完成");
t.Start();
if(t.ThreadState==ThreadState.Stopped)
MessageBox.Show("完成");
#5
invoke 2楼。
#6
这种做法有什么意义呢?
为什么不直接fun();然后msg ?
为什么不直接fun();然后msg ?
#7
或者干脆你用一部调用,别用现成了
#8
异步调用
#9
也可以把MessageBox.Show("完成"); 放到另一个线程里面去啊,两个线程可以用线程锁来进行控制的,当运行A线程后,再去运行后面的线程的,
。。。
lock (qqMain.myUsering)
{
readInfo = myPort.ReadInfo();
}
。。。
。。。
lock (qqMain.myUsering)
{
readInfo = myPort.ReadInfo();
}
。。。
#10
Thread t = new Thread(delegate() {fun();});
t.Start();
while(t.ThreadState!=ThreadState.Stopped){}
MessageBox.Show("完成");
t.Start();
while(t.ThreadState!=ThreadState.Stopped){}
MessageBox.Show("完成");
#11
public Form1()
{
InitializeComponent();
doSomeThred();
}
/// <summary>
/// 异步线程
/// </summary>
private void doSomeThred()
{
doThreadSynch();
}
private void DoSomeThing()
{
try
{
this.richTextBox1.Text += "dobegin\r\n";
Thread.Sleep(2000);
this.richTextBox1.Text += "doend\r\n";
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
private void CallBackMethod(IAsyncResult ar)
{
doDelegate d = (doDelegate)ar.AsyncState;
this.richTextBox1.Text += "Threadend\r\n";
MessageBox.Show("调用完毕");
d.EndInvoke(ar);
}
private delegate void doDelegate();
private void doThreadSynch()
{
doDelegate dlg = new doDelegate(DoSomeThing);
AsyncCallback acb = new AsyncCallback(CallBackMethod);
this.richTextBox1.Text += "ThreadBegin\r\n";
IAsyncResult iar = dlg.BeginInvoke(acb, dlg);
}
#12
找一个msdn看看关于System.Threading.WaitHandle的例子
#13
异步回调或使用线程同步
或则在MessageBox前用Thread.join 好像可以
或则在MessageBox前用Thread.join 好像可以
#14
多看看,多学习学习