当每次写入超过间隔时,在Tick事件中写入文件 [英] writing files in the Tick events when each write takes longer than the interval

查看:83
本文介绍了当每次写入超过间隔时,在Tick事件中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个计时器。在每个刻度,比如0.1秒,我写一个文件。


如果写文件需要超过0.1秒,应用程序将无法正常工作

正确。


如果之前的文件写完了,我怎么能在tick事件中告诉我

当时可以跳过写作?


我用Bitmap.Save方法写的。


也许我可以同时打开,写入,关闭?


任何想法?


如果Click事件需要0.3秒才能退出,会发生什么。


点击事件堆然后直接来到对方或是过去的那些只是错过了吗?

谢谢


解决方案

8月1日,9:33 * am,AAaron123 < aaaron ... @ roadrunner.comwrote:


我有一个计时器。在每个刻度,比如0.1秒,我写一个文件。


如果写文件需要超过0.1秒,应用程序将无法正常工作

正确。


如果上一个文件写完后我怎么能在tick事件中告诉我

当时可以跳过写作?

我用Bitmap.Save方法写的。


也许我可以同时打开,写入,关闭?


任意想法?


如果* Click事件需要0.3秒才能退出,会发生什么。


点击事件堆积然后来马上就错过了

过去的那些?


谢谢



你需要找到一个不依赖于时间的解决方案,否则你将花费剩余的项目生命调试竞争条件。


是否可以使用消息队列来跟踪写入?勾选

事件将写入队列,然后更改可能是异步写入队列的



另外,为什么不将位图保留在内存中并在更改完成后将其写入文件




谢谢,


Seth Rowe [MVP]
http://sethrowe.blogspot .com /


线程怎么样?


" AAaron123" < aa ******* @ roadrunner.com写信息

新闻:e0 ************** @ TK2MSFTNGP02.phx.gbl ...


我有一个计时器。在每个刻度,比如0.1秒,我写一个文件。


如果写文件需要超过0.1秒,应用程序将无法正常工作

正确。


如果以前的文件写完了,怎么能在tick事件中告诉我

那时我可以跳过写作了吗?


我用Bitmap.Save方法写的。


也许我可以同时打开,写入,关闭?


任何想法?


如果Click事件需要0.3秒才能退出,会发生什么。


点击事件堆起来然后直接来到或者是

过去的那些只是错过了?


谢谢


Aaron,


为什么不在背景工作者中编写文件同步。


queue class将是一个完整的greath类。


Cor


" AAaron123" < aa ******* @ roadrunner.comschreef在bericht

新闻:e0 ************** @ TK2MSFTNGP02.phx.gbl ...


>我有一个计时器。在每个刻度,比如0.1秒,我写一个文件。


如果写文件需要超过0.1秒,应用程序将无法正常工作

正确。


如果以前的文件写完了,怎么能在tick事件中告诉我

那时我可以跳过写作了吗?


我用Bitmap.Save方法写的。


也许我可以同时打开,写入,关闭?


任何想法?


如果Click事件需要0.3秒才能退出,会发生什么。


点击事件堆起来然后直接来到或者是

过去的那些只是错过了?


谢谢


I have a timer. At each tick, say 0.1 second, I write a file.

If it takes more than 0.1 second to write the file the app will not work
correctly.

How can I tell in the tick event if the previous file finished writing so I
can skip writing at that time?

I write using the Bitmap.Save method.

Maybe I could Open, Write, Close synchronously??

Any ideas?


What happens if the Click event takes more that 0.3 seconds to exit.

Do the click events pile up and then come right after each other or are the
past ones simply missed?
Thanks


解决方案

On Aug 1, 9:33*am, "AAaron123" <aaaron...@roadrunner.comwrote:

I have a timer. At each tick, say 0.1 second, I write a file.

If it takes more than 0.1 second to write the file the app will not work
correctly.

How can I tell in the tick event if the previous file finished writing soI
can skip writing at that time?

I write using the Bitmap.Save method.

Maybe I could Open, Write, Close synchronously??

Any ideas?

What happens if *the Click event takes more that 0.3 seconds to exit.

Do the click events pile up and then come right after each other or are the
past ones simply missed?

Thanks

You need to find a solution that doesn''t rely on time, otherwise you
will spend the rest of the project''s life debugging race conditions.

Is it possible to use a message queue to track the writes? The tick
event would write to the queue, and then the the changes could be
written out from the queue asynchronously.

Also, why not just keep the bitmap in memory and write it to a file
when the changes are done?

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/


what about thread?

"AAaron123" <aa*******@roadrunner.comwrote in message
news:e0**************@TK2MSFTNGP02.phx.gbl...

I have a timer. At each tick, say 0.1 second, I write a file.

If it takes more than 0.1 second to write the file the app will not work
correctly.

How can I tell in the tick event if the previous file finished writing so
I can skip writing at that time?

I write using the Bitmap.Save method.

Maybe I could Open, Write, Close synchronously??

Any ideas?


What happens if the Click event takes more that 0.3 seconds to exit.

Do the click events pile up and then come right after each other or are
the past ones simply missed?
Thanks


Aaron,

Why not do the writing of the file assynchronous in a backgroundworker.

The queue class will be a greath class to fullfil that.

Cor

"AAaron123" <aa*******@roadrunner.comschreef in bericht
news:e0**************@TK2MSFTNGP02.phx.gbl...

>I have a timer. At each tick, say 0.1 second, I write a file.

If it takes more than 0.1 second to write the file the app will not work
correctly.

How can I tell in the tick event if the previous file finished writing so
I can skip writing at that time?

I write using the Bitmap.Save method.

Maybe I could Open, Write, Close synchronously??

Any ideas?


What happens if the Click event takes more that 0.3 seconds to exit.

Do the click events pile up and then come right after each other or are
the past ones simply missed?
Thanks


这篇关于当每次写入超过间隔时,在Tick事件中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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