@andy301086

Как работать с windows service?

Добрый день всем. Недавно пришлось поработать с windows service (создание, развертывание на машине). Столкнулся с такой проблемой что сервис иногда при старте падает и не запускается. Далее проходит иногда 1 минута или чуть больше времени и при повторном его запуске (ничего не изменяя в нем!!!!!) все отлично стартует и работает. Возможно кто нить сталкивался с такой проблемой как этого можно избежать? Буду благодарен любому совету. Спасибо
  • Вопрос задан
  • 293 просмотра
Пригласить эксперта
Ответы на вопрос 2
Spetros
@Spetros
IT-шник
Для падающих программ принято проводить отладку.
К сожалению, по такой постановке вопроса отладку не провести.
Советую обратиться к MSDN и сравнить требования изложенные там со своей программой.
Ответ написан
Комментировать
artem_b89
@artem_b89
Сетевой бездельник
Пробуйте подключить WinDBG на старте сервиса, собрать дамп и его уже исследовать.
Сделать это можно как написано тут:
Configure a service to start with the WinDbg debugger attached
You can use this method to debug services if you want to troubleshoot service-startup-related problems.
Configure the "Image File Execution" options. To do this, use one of the following methods:
Method 1: Use the Global Flags Editor (gflags.exe)
Start Windows Explorer.
Locate the gflags.exe file on your computer.

Note The gflags.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.
Run the gflags.exe file to start the Global Flags Editor.
In the Image File Name text box, type the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
Under Destination, click to select the Image File Options option.
Under Image Debugger Options, click to select the Debugger check box.
In the Debugger text box, type the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:\Program Files\Debugging Tools for Windows\windbg.exe
Click Apply, and then click OK to quit the Global Flags Editor.
Method 2: Use Registry Editor
Click Start, and then click Run. The Run dialog box appears.
In the Open box, type regedit, and then click OK to start Registry Editor.
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows

In Registry Editor, locate, and then right-click the following registry subkey:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
Point to New, and then click Key. In the left pane of Registry Editor, notice that New Key #1 (the name of a new registry subkey) is selected for editing.
Type ImageName to replace New Key #1, and then press ENTER.

Note ImageName is a placeholder for the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
Right-click the registry subkey that you created in step e.
Point to New, and then click String Value. In the right pane of Registry Editor, notice that New Value #1, the name of a new registry entry, is selected for editing.
Replace New Value #1 with Debugger, and then press ENTER.
Right-click the Debugger registry entry that you created in step h, and then click Modify. The Edit String dialog box appears.
In the Value data text box, type DebuggerPath, and then click OK.

Note DebuggerPath is a placeholder for the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following:
C:\Progra~1\Debugg~1\windbg.exe

А также пишите логи, для этого могу рекомендовать log4net.

Также на хабре были статьи:
habrahabr.ru/post/127828
habrahabr.ru/post/89220
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы