定时器睡眠1/10秒 [英] Timer to sleep 1/10th of a second

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

问题描述

我需要检查是否存在文件(文件名和文件夹

已知)。该文件可以在文件检查的

开始之前或之后的任何时间创建。由于我不想给CPU带来负担,我想我会创建一个计时器并以1/10秒的间隔休眠。当

找到这个文本文件时,程序将打开,读取,关闭和删除

。然后它会再次等待这个文件的存在(永远)。


有人请告诉我在

vbnet中完成这项工作的必要性吗? br />

I need to check for the existence of a file (the filename and folder
are known). The file may be created at any time, before or after the
start of the file check. As I do not want to burden the CPU, I figured
I would create a timer and sleep for 1/10th of a second interval. When
it finds this text file, the program will open, read, close and delete
it. Then it will wait again for the existence of this file (forever).

Could someone please tell me what is necessary to accomplish this in
vbnet?

推荐答案

查看FileSystemWatcher组件

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


HTH,

格雷格


" moti" <莫**** @ hotmail.com>在消息中写道

news:12 ******************************** @ 4ax.com ...
Check out the FileSystemWatcher component

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

HTH,
Greg

"moti" <mo****@hotmail.com> wrote in message
news:12********************************@4ax.com...
我需要检查是否存在文件(文件名和文件夹已知)。可以在文件检查开始之前或之后的任何时间创建文件。因为我不想给CPU带来负担,我想我会创建一个计时器并以1/10秒的间隔休眠。当它找到这个文本文件时,程序将打开,读取,关闭和删除它。然后它会再次等待这个文件的存在(永远)。

有人可以告诉我在
vbnet中有什么必要吗?
I need to check for the existence of a file (the filename and folder
are known). The file may be created at any time, before or after the
start of the file check. As I do not want to burden the CPU, I figured
I would create a timer and sleep for 1/10th of a second interval. When
it finds this text file, the program will open, read, close and delete
it. Then it will wait again for the existence of this file (forever).

Could someone please tell me what is necessary to accomplish this in
vbnet?






在表单中添加一个计时器控件,将时间间隔设置为100

毫秒。


Ken

------------------

" moti" <莫**** @ hotmail.com>在消息中写道

news:12 ******************************** @ 4ax.com ...

我需要检查是否存在文件(文件名和文件夹

已知)。该文件可以在文件检查的

开始之前或之后的任何时间创建。由于我不想给CPU带来负担,我想我会创建一个计时器并以1/10秒的间隔休眠。当

找到这个文本文件时,程序将打开,读取,关闭和删除

。然后它会再次等待这个文件的存在(永远)。


有人请告诉我在

vbnet中完成这项工作的必要性吗? br />
Hi,

Add a timer control to your form set the interval to 100
milliseconds.

Ken
------------------
"moti" <mo****@hotmail.com> wrote in message
news:12********************************@4ax.com...
I need to check for the existence of a file (the filename and folder
are known). The file may be created at any time, before or after the
start of the file check. As I do not want to burden the CPU, I figured
I would create a timer and sleep for 1/10th of a second interval. When
it finds this text file, the program will open, read, close and delete
it. Then it will wait again for the existence of this file (forever).

Could someone please tell me what is necessary to accomplish this in
vbnet?


" moti" <莫**** @ hotmail.com> schrieb:
"moti" <mo****@hotmail.com> schrieb:
我需要检查是否存在文件(文件名和文件夹已知)。可以在文件检查开始之前或之后的任何时间创建文件。因为我不想给CPU带来负担,我想我会创建一个计时器并以1/10秒的间隔休眠。当它找到这个文本文件时,程序将打开,读取,关闭和删除它。然后它会再次等待这个文件的存在(永远)。
I need to check for the existence of a file (the filename and folder
are known). The file may be created at any time, before or after the
start of the file check. As I do not want to burden the CPU, I figured
I would create a timer and sleep for 1/10th of a second interval. When
it finds this text file, the program will open, read, close and delete
it. Then it will wait again for the existence of this file (forever).




您可以在表单中添加''System.Windows.Forms.Timer'',相应地设置间隔

并为其'Tick'事件添加处理程序。在那里你可以放置用于检查文件是否存在的

代码。


或者你可以使用这样的东西:


\\\

执行Ultil File.Exists(...)OrElse QuitApplication

Thread.Sleep(10)

循环

///


-

MS Herfried K. Wagner

MVP < URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>



You can add a ''System.Windows.Forms.Timer'' to you form, set the interval
accordingly and add a handler to its ''Tick'' event. There you can place the
code used to check if the file exists.

Alternatively you could use something like this:

\\\
Do Ultil File.Exists(...) OrElse QuitApplication
Thread.Sleep(10)
Loop
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于定时器睡眠1/10秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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