锁定资源(图像文件)管理 [英] Locked resources (image files) management

查看:83
本文介绍了锁定资源(图像文件)管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序是桌面文档管理系统。 (扫描文档的)图像文件存储在共享的网络文件夹中,并且其索引存储在数据库中。现在,当显示选定文档页面的图像时,用户可以选择删除它(通过上下文菜单)。问题是,如果我尝试执行此操作,那么它将抛出异常(资源已锁定),并且可以将其显示在屏幕上。因此,当前我维护一个持久的删除队列。应用启动后,我进入队列并删除文档的页面,这些文档的索引已从数据库中删除,并且由于未显示索引而成功删除,但这似乎是很糟糕的代码(我的意思是可以,但不能

The application is a desktop document management system. Image files (of scanned docs) are stored within a shared network folder and its indices within a database. Now, when the image of a selected document page is displayed the user has the option to delete it (via a contextual menu). The problem is, if I try to do this then it throws an exception (the resource is locked) which has all the sense given that it's being shown on screen. So, currently I maintain a persistent delete queue. Once the app starts I go to the queue and delete the pages of the documents whose indices were deleted from DB and given that they aren't being displayed the deletion succeed but this seems to be pretty bad code (I mean it works, but not as clean as it should, I guess).

我的快速解决方案有多糟糕。假设该应用程序是单用户,则用户需要加注星标才能使用它。这是一个非常糟糕的主意还是我可以使用其他路径来实现。

How bad my quick solution is. Given that the app is single-user then the user needs to star the app to use it. Is this a very bad idea or can I implemented using another path.

通过将其绑定到当前文件来显示图像(在文档查看器中):

The images are shown (within the document viewer) by binding it to the current file:

查看:

<Image Name="PageViewedPath" Margin="20" Grid.Column="0" />

ViewModel:

ViewModel:

public string PageViewedPath { get; set; }

一旦用户单击下一个或上一个,我就会进行更改(在ViewModel中的PageViewedPath中)。也许问题出在我无法详细控制的绑定上,我正在使用Caliburn Micro,所以这就是为什么仅通过设置映像名称即可完成绑定的原因。

And once the user clicks next or previous I change (within the ViewModel the PageViewedPath). Maybe the problem is this binding which I can't control in detail, I'm using Caliburn Micro so that's why just by setting the image name the binding is done.

我认为也许可以覆盖此绑定并在显示之前创建图像的硬拷贝必须可行,但是我不确定它是否会或更糟,如何实现。

I think maybe overriding this binding and creating a hardcopy of the image before is being shown must work but I'm not sure if it will and worse, how to do it.

推荐答案

在我开发的使用图像池的应用程序中,我遇到了类似的问题。尽管不再显示图像,但是文件已锁定并且无法删除。

I've had a similar problem in an application I developed that was using an image pool. Although the image was not displayed anymore, the file was locked and could not be deleted.

我通过使用 BitmapCacheOption.OnLoad加载图像解决了我的问题。 ,类似这样:

I solved my problem by loading images with BitmapCacheOption.OnLoad, something like this:

Image myImage = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();

bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = imageUri;

// End initialization.
bi.EndInit();
myImage.Source = bi;

这里是指向msdn帖子的链接,该链接显示了如何使用xaml中的BitmapCacheOption:

Here's a link to an msdn post that shows how to use BitmapCacheOption from xaml:

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3cb97997-941f-42a8-a03b-f84b152c1139/

这篇关于锁定资源(图像文件)管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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