Windows服务don';t运行正常c#
如果我调试或作为控制台应用程序运行,我的windows服务将正常运行,但如果我安装,它将显示在服务中,但根本不会运行。请帮忙 这是主要功能Windows服务don';t运行正常c#,c#,windows-services,C#,Windows Services,如果我调试或作为控制台应用程序运行,我的windows服务将正常运行,但如果我安装,它将显示在服务中,但根本不会运行。请帮忙 这是主要功能 static void main(){ if (Environment.UserInteractive) { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Service
static void main(){
if (Environment.UserInteractive)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Service1";
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
//di.Delete();
}
StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Service1\\program.txt", true);
sw.WriteLine(DateTime.Now.ToString() + " : Here if\n");
// sw.WriteLine("userprofile " + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + " : ");
// sw.WriteLine("application data " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + " : ");
sw.Flush();
sw.Close();
Console.WriteLine("here1");
Service1 service1 = new Service1();
string[] args = { "Kun", "Singh" };
service1.TestStartupAndStop(args);
}
else
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Service1";
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
//di.Delete();
}
StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Service1\\program.txt", true);
sw.WriteLine(DateTime.Now.ToString() + " : Here else\n");
// sw.WriteLine("userprofile " + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + " : ");
// sw.WriteLine("application data " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + " : ");
sw.Flush();
sw.Close();
Console.WriteLine("here2");
// Put the body of your old Main method here.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
// RunAsync().Wait();
Service1 myServ = new Service1();
myServ.write("hello bb");
Console.Read();
}
可能是因为Environment.UserInteractive返回false。您正在运行的服务意味着没有用户界面。看 UserInteractive属性为Windows进程或 像IIS这样运行时没有用户界面的服务。如果这个属性 如果为false,则不要显示模式对话框或消息框,因为存在 没有供用户交互的图形用户界面
我建议尝试将条件更改为if(!Environment.UserInteractive)我刚做了一个新的WIX设置,现在它可以工作了,不过还有第二个问题。。。我在我的windows服务项目中有一些引用,当我安装和运行时,我有一个日志文件说xxx.dll丢失了,我如何将它们包括在安装程序中 我有以下参考->jose-jwt.dll,实体框架
那么如何设置参考文件您是否确保该服务正在运行?转到“运行”并键入服务。msc按enter键查看所有正在运行的服务。它仅在运行我甚至尝试重新启动。。。。代码很好,主要是因为在调试模式下,所有文件都已写入,而且数据库也正常工作。。。但是如果使用installutil.exe,它会安装,但不会发生任何事情。。。。我不知道之前它在示例程序中运行时有什么问题。。。。有什么方法可以调试seeply吗?我甚至尝试了[Conditional(“debug_SERVICE”)]private static void DebugMode(){Debugger.Break()}它在调试模式下工作我不知道,但我在同一个解决方案中添加了新的wix设置,现在一切都正常工作了