【发布时间】:2013-06-24 14:10:31
【问题描述】:
我正在尝试用 C# 编写一个项目 Windows 服务。
我想将文件夹复制到另一个目录。我写了代码,一切都很完美
DirectoryInfo source = new DirectoryInfo("C:\\belgeler");
DirectoryInfo target = new DirectoryInfo("E:\\Backup");
这是正确的实现,但是当我写这个时......
DirectoryInfo source = new DirectoryInfo(from_path);
DirectoryInfo target = new DirectoryInfo(to_path);
错误是'A field initializer cannot reference the non-static 字段、方法或属性 'BACKUP(myproject_name).Service1.veri'
//string to_path = Registry.LocalMachine.GetValue("ToPath").ToString();
//string from_path = Registry.LocalMachine.GetValue("FromPath").ToString();
此代码块正在运行控制台应用程序,但在 Windows 服务中却不是。
【问题讨论】:
-
是非静态字段、方法还是属性? ;)
-
"此代码块正在运行控制台应用程序,但在 Windows 服务中不是。"它作为控制台应用程序编译,但不是作为 Windows 服务?我非常怀疑...
-
from_path和to_path是您班级的成员,还是局部变量?source或target呢? -
好的,我解决了。为了能够实现,它会在方法中。
标签: c# .net directoryinfo