Sharepoint 计时器作业进程不释放文件 (IOException)

发布于 2024-09-07 15:25:06 字数 558 浏览 1 评论 0原文

我创建了一个计时器作业(通过功能部署),在主机服务器的文件系统中创建一个文件。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2024-09-14 15:25:06

当您使用Using关键字时,您不需要调用dispose,因为Using会为您做这件事。

when you use Using keyword you do not need to call dispose, as Using does it for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文