多少线程? [英] How many threads?
问题描述
假设我有一个带有两个独立的System.Windows.Forms.Timer计时器的Windows窗体应用程序,它们的Tick方法具有以下代码:
Let's say I have a Windows Forms application with two independent System.Windows.Forms.Timer timers, and their Tick methods have the following code:
Private Sub timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles timer1.Tick
Dim pe1 As Timer1Delegate = New Timer1Delegate(AddressOf ProcessTimer1)
pe1.BeginInvoke(New AsyncCallback(AddressOf Timer1Complete), Nothing)
End Sub
Private Sub timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles timer2.Tick
Dim pe2 As Timer2Delegate = New Timer2Delegate(AddressOf ProcessTimer2)
pe2.BeginInvoke(New AsyncCallback(AddressOf Timer2Complete), Nothing)
End Sub
我相信TICK方法将在GUI线程上处理。对吗?$
I believe that the TICK methods will be handled on the GUI thread. Right?
ProcessTimer1()方法和ProcessTimer2()方法是否在两个不同的/独立的线程上运行?
Do the ProcessTimer1() method and ProcessTimer2() method run on two different/independent threads?
推荐答案
您好,
>> 我相信TICK方法将在GUI线程上处理。对吗?
是的,timer_Tick事件不会创建新线程。
Yes, the timer_Tick event do not create a new thread.
>> ProcessTimer1()方法和ProcessTimer2()方法是否在两个不同/独立的线程上运行?
简短的回答是否定,正如Kenan所说的
此主题:
The short answer is No, as Kenan said in this thread:
BeginInvoke会将操作发布到与表单相同的线程上的消息泵的消息队列中,它不会创建新线程。
有关BeginInvoke的更多详细信息,请检查:
For more details about BeginInvoke, please check:
问候,
Stanly
这篇关于多少线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!