同时执行两个动作 [英] two action at same time

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

问题描述

大家好,我已经创建了一个小的Windows合并,在我的表单中,用户将在TextBox中输入一些数据,并且用户将保存数据,但是在后台,应该进行一些处理,例如检查数据库连接是否是否是否打开,

两种动作都应继续进行.输入数据以及连接过程
如何做到这一点.

Hi all, I have created small windows apllication, in my form user will enter some data in the TextBox and user will save the data, but in background there should some process go on like checking the database connection whether it''s open or not,

Both action should go on. Entering data as well as connectivity process
How to do this.

推荐答案

您可以使应用程序成为多线程的,例如,参见CodeProject的文章 [
You can make your application mutithreaded, see, for instance, the CodeProject''s article "Introduction to making multithreaded VB.NET Apps"[^].


看看使用BackgroundWorker线程: MSDN [ ^ ]-这可能是最简单的线程入门的方法.该链接包含一个示例.
Look at using a BackgroundWorker Thread: MSDN[^] - it is probably the simplest way to get started with threading. The link includes an example.


不能保证不会同时发生任何事情,至少在非实时系统中不会如此.
如果您在一个线程中执行某项操作,则您的操作将连续执行.如果您在不同的线程中进行操作,它们可能会在时间上重叠,但是由于线程调度是概率性的,因此没有什么可以给您100%的保证准确的时间安排.而且,如果某些对象移动得足够快,那么类似空间间隔的相同时间"的概念甚至没有意义:-),请参阅:
http://en.wikipedia.org/wiki/Space-like#Space-like_interval [ ^ ].

—SA
Nothing can be guaranteed to happen at the same time, at least not in the non-real-time system.
If you do something in one thread, your actions follow consecutively. If you do it in different threads, they may overlap in time, but as thread scheduling is probabilistic, nothing can give you 100% guarantee exact timing. And if some objects move fast enough, the concept of the "same time" for a space-like interval does not even makes sense :-), please see:
http://en.wikipedia.org/wiki/Space-like#Space-like_interval[^].

—SA


这篇关于同时执行两个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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