让Windows尝试读取文件 [英] Keep windows trying to read a file

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

问题描述

我正在对Windows文件系统进行某种封装.

I'm working in a sort of encapsulation of the windows filesystem.

当用户请求打开文件时,Windows会调用我的驱动程序以提供数据.在正常操作中,驱动程序返回已缓存的文件内容,但是,在某些情况下,实际文件未缓存,因此我需要从网络下载该文件.

When the user request to open a file, windows calls to my driver to provide the data. In normal operation the driver return the file contents which is cached, However, in some cases the real file is not cached and I need to download it from the network.

问题是,是否有可能让Windows尝试读取文件而不阻止整个驱动器操作,要么打开文件的软件都没有,这给用户提供了取消打开过程的机会.

The question is if it's possible to keep Windows trying to read the file without blocking the entire drive operation neither the software which open the file, giving the user a chance to cancel the opening process.

首先,我尝试阻塞驱动程序,直到数据可用为止,此解决方案的实现更简单,但用户体验并不是最好的.而且,依靠网络传输不是一个好主意,传输可能会持续很多时间,并且驱动程序将一直处于阻塞状态.

At first, i tried to block the driver until data is available, this solution is the more straightforward to implement, but the user experiencie isn't the best. Moreover, relying in network transfer isn't a good idea, the transfer could last for many time and the driver will be block all that time.

我实现的第二种方法是,当文件被缓存且文件不可用时,仅返回数据,告诉窗口文件大小为0,然后在后台处理中下载文件.这样,驱动程序不会阻塞窗口,并且用户体验得到改善,但是用户需要打开文件N次,直到数据可用为止.

The second way I have implemented, consist in return only data when the file is cached and when the file isn't available tell windows that the file is 0 size length, and download the file in a background proccess. With this, the driver don't block windows, and the user experience improve, but the user need to open N times the file until data is available.

我认为最好的解决方案是返回Windows消息,如无可用数据,请在5秒钟内重试",我认为如果驱动程序将适当的错误代码返回给Windows,则可以实现,但是错误列表太长,名称并不总是如您所愿.

I think that the best solution will be to return windows a message like "No data available, try again in 5 secs", i think that if the driver return the apropiate error code to windows this could be achieved, but the error list is too long and the names aren't always as descriptive as you want.

您对此有何建议?预先感谢.

Do you have some advice implementing this? Thanks in advance.

推荐答案

您实现的行为对于驱动程序是正确的.处理慢速I/O的责任更高.例如,Windows资源管理器非常小心,不要试图完全依靠元数据从任何文件中检索甚至单个字节.

The behavior you implement is correct for a driver. The responsibility for handling slow I/O lies at a higher level. For instance, Windows Explorer is very careful in NOT trying to retrieve even a single byte from any file, relying purely on metadata.

但是,在忙碌时不要返回失败代码.正是这种失败迫使用户反复打开文件.

However, do not return a failure code when you're busy. It's that failure which would force users to repeatedly open a file.

这篇关于让Windows尝试读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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