c#

位置:IT落伍者 >> c# >> 浏览文章

使用C# 创建 Windows 服务


发布日期:2023年10月07日
 
使用C# 创建 Windows 服务
在Windows服务里面如果访问文件采用绝对路径可以如果采用相对路径和生成的服务文件在同一目录下面则要访问此程序集 下面的文件

using System;

using SystemCollectionsGeneric;

using SystemText;

using SystemReflection;

using SystemXml;

using SystemIO;

namespace HDUSearch

…{

public class IndexConfig

…{

GetValue#region GetValue

public string GetValue(string key)

…{

string assemblyFilePath = AssemblyGetExecutingAssembly()Location;

string assemblyDirPath = PathGetDirectoryName(assemblyFilePath)

XmlDocument xmlDoc = new XmlDocument()

xmlDocLoad(assemblyDirPath + \nfig

XmlNodeList nodeList = xmlDocSelectSingleNode(/configuration/appSettingsChildNodes; //获取appSettings节点的所有子节点

foreach (XmlNode xn in nodeList) //遍历所有子节点

…{

XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型

if (xeGetAttribute(keyIndexOf(key) !=

…{

return xeGetAttribute(value

break;

}

}

return ;

}

#endregion

}

}

上一篇:.Net 下信号量(Semaphore)的一种实现

下一篇:c#DIY随机数类