[英].NET Console App throws error when scheduled. Runs fine when executed manually
So I decided to make a console application to automate some repetitive jobs that I generally do on a daily basis.所以我决定制作一个控制台应用程序来自动化一些我通常每天都会做的重复性工作。 The objective is to move some files to a network location as backup.
目标是将一些文件移动到网络位置作为备份。 The application runs fine when executed manually.
手动执行时,应用程序运行良好。 But when scheduled, it throws an error.
但是在计划时,它会引发错误。 On examining the log file (to which all program output is mapped), I found the following stack trace and exception message:
在检查日志文件(所有程序 output 都映射到该文件)时,我发现了以下堆栈跟踪和异常消息:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName)
at automateDump.Program.Main(String[] args) in D:\software\automateDump\Program.cs:line 78
The user name or password is incorrect.
I'm using the File.Copy(src, dest)
method in System.IO
.我在
System.IO
中使用File.Copy(src, dest)
方法。
And for context, the file paths are:对于上下文,文件路径是:
Source: D:\u01\test.file
.来源:
D:\u01\test.file
。 Destination: \\NetDrive\test.file
目的地:
\\NetDrive\test.file
Any help would be appreciated.任何帮助,将不胜感激。
EDIT 1编辑 1
Code:代码:
if (File.Exists(movePath + et1))
{
Console.WriteLine($"Copying {et1} to network location. Size - {sizeInMegaBytes(new FileInfo(movePath + et1).Length)}");
File.Copy(movePath + et1, networkPath + et1);
Console.WriteLine("Done Copying");
}
movePath
and networkPath
are source and destination paths, and et1
is the file. movePath
和networkPath
是源路径和目标路径, et1
是文件。
sizeInMegaBytes()
is a utility function that I wrote. sizeInMegaBytes()
是我编写的实用程序 function。 It's irrelevant in this context.在这种情况下是无关紧要的。
EDIT 2编辑 2
Exception Handling code:异常处理代码:
catch (Exception ex)
{
using (logger = File.AppendText(@"D:\u01\logs.txt"))
{
logger.WriteLine($"{ex.StackTrace} \n {ex.Message}");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.