打破VB.Net中的循环 [英] Breaking up loops in VB.Net

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

问题描述

 我最近开始学习VB.Net。我正在使用VB2008版本。我正在使用Win Forms。我认为它与新版本没有太大区别。我的问题可能也适用于其他.net版本。无论如何我遇到的问题是,如何用b $ b来打破.Net中的循环,同时敲击键盘上的任何键(例如,在紧急情况下我不想寻找特定键)。在.Net之前,我用来在Qbasic做一些爱好编程。在Qbasic中我所要做的就是在循环中插入一个INKEY $()语句
来打破循环。我无法弄清楚,如何在VB.Net 2008计划中拥有类似的功能。我将不胜感激任何帮助。在此先感谢。 

 I recently started learning VB.Net. I am using VB2008 Version. I am Working with Win Forms. I assume it is not too different from the newer versions. My question probably applies to other .net Versions also. Anyway the problem I am having is, how to break up loops in .Net with hitting any key on the keyboard(for example, in an emergency situation I don't want look for a perticular key). Before .Net I use to do some hobby programming in Qbasic. In Qbasic all I have to do was insert an INKEY$() statement within in the loop to break the loop. I can not figure out, how to have a similar functionality in a VB.Net 2008 Program. I would appreciate any help. Thanks in advance. 

推荐答案

如果您正在编写控制台应用程序,您可以在循环中使用Conosle.ReadKey执行非常类似的操作。

If you are writing a console application you can do something very similar using Conosle.ReadKey in your loop.

在Windows窗体应用程序中,事情可能会更加复杂,因为键盘按下不会在表单中响应,直到它不再忙碌。 这意味着在后台线程上或以异步方式运行循环。

In a Windows Forms application things can be much trickier because the keyboard press won't respond in the form until it is no longer busy.  That means running your loop on a background thread, or in an asynchronous fashion.

你究竟是怎么做的,这完全不取决于你想要做什么。 您需要在pusedo代码中提供一个具体示例,以向我们展示您希望"暂停"的内容和原因。一个循环。

Exactly how you go about it depends no exactly what you are trying to do.  You would need to provide a concrete example in pusedo code to show us what and why you are wanting to "pause" a loop.


这篇关于打破VB.Net中的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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