是否有更简单的方法来单步执行代码,而不是通过Windows服务控制管理器启动服务,然后将调试器附加到线程?这有点麻烦,我想知道是否有一个更简单的方法.
我一直在阅读演练:在 MSDN 上的组件设计器中创建 Windows 服务应用程序。
我有一些代码并安装了我的服务:
我的代码如下:
namespace WindowsServiceWalkthrough
{
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Timers;
using System.Runtime.InteropServices;
public partial class MyNewService : ServiceBase
{
private int _eventId;
public MyNewService()
{
InitializeComponent();
if (! EventLog.SourceExists("MySource"))
{
EventLog.CreateEventSource(
"MySource",
"MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
}
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);
protected override void OnStart(string[] args)
{
var serviceStatus = new ServiceStatus
{
dwCurrentState = …Run Code Online (Sandbox Code Playgroud) Visual Studio和C#的新手。在Visual Studio 2017中构建一个名为Transactional Messaging的C#Windows服务,该服务依赖于一个名为Outbound Messaging的项目。当我开始调试并尝试在出站邮件文件上添加断点时,我得到
“此断点当前不会被命中。没有为该文档加载任何符号”
据我所知,VS仅无法为以下文件加载pdb文件:log4net.dll,Castle.Windsor.dll和Castle.Core.dll。我没有在事务消息服务中向文件添加断点的问题。我还无法识别行为模式或永久修复程序,因此此时错误似乎是随机的。一分钟后,我认为我已经找到了修复程序,当我尝试在当天晚些时候针对同一错误使用该修复程序时,我没有运气。我怀疑最近的一次停电意外关闭了我的计算机,因为它看起来可以缓存pdb文件,但是被告知这是一个长期的尝试。
我按照以下步骤调试服务:
installutil /u TransactionalMessaging.exeDebug文件夹中的VS命令行卸载Transactional Messaging Serviceinstallutil TransactionalMessaging.exeDebug文件夹中的VS命令行安装Transactional Messaging Service我尝试解决此错误的步骤:
我不确定这是否缺乏对VS,C#或代码库的理解。感谢您提供任何见解,我已经过了谷歌搜索阶段,并发布了一个新的问题作为不得已的选择。
c# windows-services visual-studio visual-studio-debugging pdb-files