Send windows message to a Windows Service

前端 未结 7 1933
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 05:57

Is there any tool to send (mimic) a windows message like \'WM_ENDSESSION\' to a windows service?

OR

How can I send a windows message to a process using C#?

7条回答
  •  我在风中等你
    2021-02-06 06:41

    Generally, services don't have windows (let alone message pumps) to receive a windows message.

    If the bug really does only happen on shutdown (as opposed to just stopping the service), it may be the case that something depends on a resource that is going away, which is not being handled gracefully (in which case, the bug fix might be to set up the service dependencies correctly). Have you tried using the remote debugging tools to attach to the process prior to shutdown?

    It's worth investigating if you can get the problem to occur without shutting down, perhaps when just stopping the service with the Service Control Manager (no need to do this programmatically, as this is a debugging scenario), in which case, you can breakpoint OnStop() in your service (I'm assuming C#) and watch what happens.

提交回复
热议问题