DoEvents的问题 [英] Problem With DoEvents

查看:39
本文介绍了DoEvents的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以附上我的代码,如果有人想看到它,但我会先尝试用一些标记代码询问我的

问题。


我在使用DoEvents时遇到问题终止我的进程。对于

示例:


Button.text = start


如果button.text = start则

button.text = stop

msgbox" Boo!"

doevent

而1 = 1

msgbox" BooHoo! 

loop

else if button.text = stop

button.text = start

msgbox" Quit Your Whining"

结束如果

好​​的,点击按钮就可以得到:

Boo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

.......


现在点击停止按钮即可获得


退出你的抱怨

BooHoo!


这没有意义。按钮已经没有=开始。这是停止

这就是为什么它运行停止代码。


由于某种原因它最后一次通过DoEvents代码。


如何在运行我的STOP代码之前正确停止DoEvents线程?


感谢您的任何建议!

I can attach my code if anyone wants to see it however I''ll try to ask my
question with some mark up code first.

I''m having a problem terminating my process while using DoEvents. For
example:

Button.text = start

If button.text = start then
button.text = stop
msgbox "Boo!"
doevent
while 1=1
msgbox "BooHoo!"
loop
else if button.text = stop
button.text = start
msgbox "Quit Your Whining"
end if
Ok, click the button and you get:
Boo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
.......

Now click the stop button and you get

Quit Your Whining
BooHoo!

That doesn''t make sense. The button already did NOT = Start. It was Stop
which is why it ran the stop code.

For some reason it goes through the DoEvents code one last time.

How can I properly stop that DoEvents thread prior to running my STOP code?

Thanks for any advise!

推荐答案

Justin写道:

< snip>
Justin wrote:
<snip>

我在使用DoEvents时遇到问题终止我的进程。对于

示例:


Button.text = start


如果button.text = start则

button.text = stop

msgbox" Boo!"

doevent

而1 = 1

msgbox" BooHoo! 

loop

else if button.text = stop

button.text = start

msgbox" Quit Your Whining"

end if if
I''m having a problem terminating my process while using DoEvents. For
example:

Button.text = start

If button.text = start then
button.text = stop
msgbox "Boo!"
doevent
while 1=1
msgbox "BooHoo!"
loop
else if button.text = stop
button.text = start
msgbox "Quit Your Whining"
end if



< snip>

<snip>


现在点击停止按钮即可获得


退出你的抱怨

BooHoo!


这没有意义。按钮已经没有=开始。这是Stop

这就是为什么它运行停止代码。


由于某种原因,它最后一次通过DoEvents代码。
Now click the stop button and you get

Quit Your Whining
BooHoo!

That doesn''t make sense. The button already did NOT = Start. It was Stop
which is why it ran the stop code.

For some reason it goes through the DoEvents code one last time.



< snip>


我不认为你的标记翻译了你的行动序列>
代码非常忠实。例如,标记代码只调用DoEvents

一次,看起来你期望它运行几次。也许

修改标记或发布实际代码会提供更好的问题视图。


请记住,然而,VB.Net中的DoEvents可能比VB经典更危险/不可预测/不可判坏,因为VB.Net

必须考虑到更多的东西。事件处理周期。对于

示例,启动DoEvents执行

线程间UI更新时来自meain线程,你可能会崩溃应用程序。


还有其他方法来实现你(似乎)想要,并且

DoEvents就在这个列表中,即使在那里也是如此。


HTH。


问候,


布兰科。

<snip>

I don''t think your markup translates the sequence of actions from your
code very faithfully. For instance, the markup code only calls DoEvents
once, and it seems you''re expecting it to run several times. Maybe
revising the markup or posting the actual code would provide a better
view of the problem.

Keep in mind, however, that DoEvents in VB.Net can be even more
dangerous/unpredictable/undebuggable than in VB classic, cause VB.Net
must account for many more things in the event processing cycle. For
Example, launch a "DoEvents" from the meain thread when performing
inter-thread UI updates and you may crash the application.

There are other ways to accomplish what you (seem to) want, and
DoEvents is way down in this list, if even there at all.

HTH.

Regards,

Branco.


贾斯汀,


只看一下threading.Thread.sleep(毫秒)比其余的要好

显然对你来说很清楚。

http://msdn.microsoft.com/library/de。 ..sleeptopic.asp


我希望这会有所帮助,


Cor


贾斯汀 < Ju **** @ noSpam.comschreef in bericht

news:eD ************** @ TK2MSFTNGP02.phx.gbl ...
Justin,

Just look at threading.Thread.sleep(milliseconds) than the rest will
obviously be clear to you.

http://msdn.microsoft.com/library/de...sleeptopic.asp

I hope this helps,

Cor

"Justin" <Ju****@NoSpam.comschreef in bericht
news:eD**************@TK2MSFTNGP02.phx.gbl...

>如果有人想看到它,我可以附上我的代码但是我会首先用一些标记代码来询问我的问题。


我在使用DoEvents时遇到问题终止我的进程。对于

示例:


Button.text = start


如果button.text = start则

button.text = stop

msgbox" Boo!"

doevent

而1 = 1

msgbox" BooHoo! 

loop

else if button.text = stop

button.text = start

msgbox" Quit Your Whining"

结束如果


好​​的,点击按钮即可获得:

Boo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

......


现在点击停止按钮即可获得


退出你的抱怨

BooHoo!


这没有意义。按钮已经没有=开始。这是停止

这就是为什么它运行停止代码。


由于某种原因它最后一次通过DoEvents代码。


如何在运行我的STOP

代码之前正确停止DoEvents线程?


感谢您的任何建议!
>I can attach my code if anyone wants to see it however I''ll try to ask my
question with some mark up code first.

I''m having a problem terminating my process while using DoEvents. For
example:

Button.text = start

If button.text = start then
button.text = stop
msgbox "Boo!"
doevent
while 1=1
msgbox "BooHoo!"
loop
else if button.text = stop
button.text = start
msgbox "Quit Your Whining"
end if
Ok, click the button and you get:
Boo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
......

Now click the stop button and you get

Quit Your Whining
BooHoo!

That doesn''t make sense. The button already did NOT = Start. It was Stop
which is why it ran the stop code.

For some reason it goes through the DoEvents code one last time.

How can I properly stop that DoEvents thread prior to running my STOP
code?

Thanks for any advise!



在你变得更加困惑之前...(这个(据我所知)没有什么可以用来支付
使用线程)


正如所指出的那样,你的伪代码不一定与你写的代码相同。但是你的问题也表明存在一个误解,因为你写了它再次通过DoEvents代码。没有

DoEvents代码只需要调用DoEvents就可以给O / S一个

的机会来处理没有被处理的低优先级事件。


也尝试避免构造如:1 = 1.这是一个无法控制的

条件,a)形式不佳,b)过于复杂,因为1 = 1等于

到真为什么真的不仅仅是循环吗?但是再一次不要这样做只是给它

一个诚实的条件来测试。


我认为你最好发布1)一个描述你是什​​么

尝试和2)实际代码(如果它是特别长的话,减少到必需品。)或许甚至3)为什么你这样做因为它是当它正在运行时会非常讨厌:-)


Tom

" Justin" < Ju **** @ NoSpam.com写信息

新闻:eD ************** @ TK2MSFTNGP02.phx.gbl ...
Before you get more confused... (this has (as far as I can see) nothing to
do with threading)

As was pointed out your pseudocode isn''t likely the same as the code you
wrote. But your question also indicates there is a misunderstanding since
you write "it goes through the DoEvents code one more time". There is no
"DoEvents code" there is simply a call to DoEvents which gives the O/S a
chance to process low-priority events that are not getting processed.

Also try to avoid constructs like: while 1 = 1. It is an uncontrollable
condition which is a) poor form and b) overly complex since 1 = 1 is equal
to True why not just loop while True? But again don''t do that just give it
an honest condition to test for.

I think you would be better off posting 1) a description of what you are
attempting and 2) the actual code (reduced to the essentials if it is
particularly long.) Perhaps even 3) why you doing this since it is going to
be very annoying when it''s running :-)

Tom
"Justin" <Ju****@NoSpam.comwrote in message
news:eD**************@TK2MSFTNGP02.phx.gbl...

>如果有人想看到它,我可以附上我的代码但是我会首先用一些标记代码来询问我的问题。


我在使用DoEvents时遇到问题终止我的进程。对于

示例:


Button.text = start


如果button.text = start则

button.text = stop

msgbox" Boo!"

doevent

而1 = 1

msgbox" BooHoo! 

loop

else if button.text = stop

button.text = start

msgbox" Quit Your Whining"

结束如果


好​​的,点击按钮即可获得:

Boo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

BooHoo!

......


现在点击停止按钮即可获得


退出你的抱怨

BooHoo!


这没有意义。按钮已经没有=开始。这是停止

这就是为什么它运行停止代码。


由于某种原因它最后一次通过DoEvents代码。


如何在运行我的STOP

代码之前正确停止DoEvents线程?


感谢您的任何建议!
>I can attach my code if anyone wants to see it however I''ll try to ask my
question with some mark up code first.

I''m having a problem terminating my process while using DoEvents. For
example:

Button.text = start

If button.text = start then
button.text = stop
msgbox "Boo!"
doevent
while 1=1
msgbox "BooHoo!"
loop
else if button.text = stop
button.text = start
msgbox "Quit Your Whining"
end if
Ok, click the button and you get:
Boo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
BooHoo!
......

Now click the stop button and you get

Quit Your Whining
BooHoo!

That doesn''t make sense. The button already did NOT = Start. It was Stop
which is why it ran the stop code.

For some reason it goes through the DoEvents code one last time.

How can I properly stop that DoEvents thread prior to running my STOP
code?

Thanks for any advise!



这篇关于DoEvents的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆