Sharepoint 计时器作业进程不释放文件 (IOException)
我创建了一个计时器作业(通过功能部署),在主机服务器的文件系统中创建一个文件。
private static void myMethod(Byte[] results, string fileName)
{
using (FileStream stream = File.OpenWrite(fileName))
{
stream.Write(results, 0, results.Length);
stream.Close();
stream.Dispose();
}
}
FileStream 构造函数中的 FileAccess.Write、FileShare 等也不起作用。 在计时器服务重新启动之前,无论是在计时器进程内还是在 Windows 资源管理器中使用管理员权限都无法删除所创建的文件。
计时器作业是通过 NETWORKService 执行的。
在控制台应用程序中(在管理员权限下运行相同的代码)它可以正常工作。
我决定暂时在文件系统中创建随机文件以快速解决我的问题,但这不是最好的情况。
I created a timer job (via Feature Deployment) that creates a file in hostserver´s filesystem.
private static void myMethod(Byte[] results, string fileName)
{
using (FileStream stream = File.OpenWrite(fileName))
{
stream.Write(results, 0, results.Length);
stream.Close();
stream.Dispose();
}
}
also FileAccess.Write, FileShare etc. in FileStream constructor doesnt work.
The created file cannot be deleted neither within the timer process nor with Administrator privileges in Windows Explorer until the timer service has been restarted.
The timer job is been executes via NETWORKService.
In a console application (runs the same code under Administrator privileges) it works properly.
I decided to temporaly create random files in filesystem to sove my problem quickly, but It is not the best case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用Using关键字时,您不需要调用dispose,因为Using会为您做这件事。
when you use Using keyword you do not need to call dispose, as Using does it for you.