如何确定,因为一个共享冲突,如果抛出IOException? [英] How do I determine if an IOException is thrown because of a sharing violation?

查看:169
本文介绍了如何确定,因为一个共享冲突,如果抛出IOException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#应用程序,我想将文件复制到一个新的位置。有些时候我需要覆盖现有文件。 发生这种情况时我收到System.IO.IOException。我想从一个共享冲突恢复,但我怎么确定IOException异常返回,因为该目标文件正在使用中而不是其他原因?我可以寻找的过程,因为它是被另一个进程无法访问该文件。消息......但我不喜欢这个主意。

I have a C# application and I want to copy a file to a new location. Some times I need to overwrite an existing file. when this happens I receive a System.IO.IOException. I want to recover from a Sharing violation but how do I determine that IOException was returned because the destination file is in use rather then some other reason? I could look for the "The process cannot access the file because it is being used by another process." message... But I don't like that idea.

推荐答案

这<一href="http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.languages.csharp/2007-08/msg02156.html"相对=nofollow>文章解释如何得到异常HRESULT因此可以判断错误原因。

This article explains how to get the exception HRESULT so you can determine the error cause.

这篇关于如何确定,因为一个共享冲突,如果抛出IOException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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