Siz*_*ons 4 c# windows-services task-parallel-library
我希望我现在可以在我的电脑上放一枚手榴弹.我很沮丧,因为我不明白为什么我的应用程序不会使用installUtil安装.
我现在只看了这个链接: Windows服务安装结束回滚,不幸的是那里的那些建议对我的情况没有帮助,在考虑到好人们发布的所有答案之后产生了以下错误.那个链接和其他人.
我已经在网上寻找任务并行处理模式的最佳实践,但到目前为止没有任何帮助.我尝试安装时遇到的最新错误如下:
.exe程序集的进度.该文件位于E:\ xxx\MyService\Service_V2.InstallLog.安装程序集'E:\ xxx\MyService\Service_V2.exe'.受影响的参数为:
logtoconsole = logfile = E:\ xxx\MyService\Service_V2.InstallLog
assemblypath = E:\ xxx\MyService\Service_V2.exe安装服务Service V2 ...已成功安装Service Service V2.在日志应用程序中创建EventLog源服务V2 ...安装服务服务V2 ...在日志应用程序中创建EventLog源服务V2 ...安装阶段发生异常.System.ComponentModel.Win32Exception:指定的服务已存在
安装的回滚阶段正在开始.请参阅日志文件的内容以获取E:\ xxx\MyService\Service_V2 .exe程序集的进度.该文件位于E:\ xxx\MyService\Service_V2.InstallLog.回滚组件'E:\ xxx\MyService\Service_V2.exe'.受影响的参数为:
logtoconsole = logfile = E:\ xxx\MyService\Service_V2.InstallLog
assemblypath = E:\ xxx\MyService\Service_V2.exe将事件日志还原到源Service V2的先前状态.将事件日志还原到源Service V2的先前状态.正在从系统中删除Service Service V2 ...已成功从系统中删除Service Service V2.回滚阶段成功完成.
事务处理安装已完成.安装失败,并且已执行回滚.
事件日志中也没有写入任何内容.
这是我的OnStart()方法:
protected override void OnStart(string[] args)
{
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
ErrorLogFileName = "Service_V2Errors" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
Service_V2LogFile = "Service_V2Log" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
ErrorLogPath = ConfigurationManager.AppSettings["Errorpath"].ToString();
CheckBatchRecord = Convert.ToInt32(ConfigurationManager.AppSettings["CheckBatchTime"].ToString());
if (!Directory.Exists(ErrorLogPath))
{
Directory.CreateDirectory(ErrorLogPath);
}
LogMessage("Starting Service " + DateTime.Now.ToString());
_ErrorLog = new StreamWriter(ErrorLogPath + "//" + ErrorLogFileName, true);
_ErrorLog.WriteLine("Error, Location, AdditionalInformation", true);
_ErrorLog.Close();
var t = Task.Run(() => Service_V2Start(), token);
try
{
t.Wait();
}
catch (AggregateException e)
{
LogMessage("Exception messages:");
foreach (var ie in e.InnerExceptions)
LogMessage(ie.GetType().Name + " : " + ie.Message);
LogMessage("\nTask status: " + t.Status);
}
finally
{
tokenSource.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
我还为编译的最终安装文件设置了编译模式.
我做了一个"sc delete Servie V2",我也检查了服务控制台,那里没有列出这样的服务.
我也尝试过InstallUtil.exe -u命令来卸载,但我仍然得到这个笨蛋错误.我现在应该怎么做?
确保您的Program.cs
文件看起来像这样:
static class Program
{
static void Main()
{
var service = new YourServiceName();
ServiceBase.Run(service);
}
}
Run Code Online (Sandbox Code Playgroud)里面的InitializeComponent()
方法确保该ServiceName
属性值是相同ServiceName
的ProjectInstaller.cs
this.ServiceName = "MyServiceName";//in the YourServiceName partial class
this.myServiceInstaller.ServiceName = "MyServiceName";//in the installer
Run Code Online (Sandbox Code Playgroud)确保您只有一个安装程序.
在为安装和卸载服务而创建的批处理文件中,请确保指向正确的文件InstallUtil.exe
.
对于64位体系结构,您可以使用 - C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe
对于32位体系结构,您可以使用 - C:\ Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
示例InstallService.bat文件:
"C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe""PathToTheExecutables\MyServiceName.exe"暂停
示例UninstallService.bat文件:
"C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe"/ u"PathToTheExecutables\MyServiceName.exe"暂停
归档时间: |
|
查看次数: |
5482 次 |
最近记录: |