How to log when windows service is being stopped by server restart c#

I want to handle when windows service is killed by task manager or by system restart.
I tried using below handler inside Timer_Elapsed method of the service timer
public void Start()
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
_myTimer= new Timer(10000);
_myTimer.Elapsed += OnElapsed;
_myTimer.AutoReset = false;
_myTimer.Start();
private void OnElapsed(object sender, ElapsedEventArgs e)
try
_myTimer.Stop();
//Work
finally
_myTimer.Start();
and even I have placed the same into Main() method of the console as I am using Topshelf for windows service.
static void Main(string[] args)
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var exitCode = HostFactory.Run(hostConfigurator =>
hostConfigurator.Service<MyService>(serviceConfigurator =>
serviceConfigurator.ConstructUsing(() => new MyService());
serviceConfigurator.WhenStarted(MyService => MyService.Start());
serviceConfigurator.WhenStopped(MyService=> MyService.Stop());
hostConfigurator.RunAsLocalSystem();
hostConfigurator.SetDisplayName("MyService");
hostConfigurator.SetDescription("MyService");
hostConfigurator.SetServiceName("MyService");
hostConfigurator.UseLog4Net();
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
File.AppendAllText(@"C:\Crash.txt", "Main Termination");
In either scenario the handler is not getting called when I kill the windows service process from task manager or system restart. Even TopShelf is not logging "UnhandledServiceException" exit code.
I have searched for all possible ways but no luck. Could any one please help me in this.
Thanks

Hello RamJS,
You could have a try to use the Process.Exited Event to handle such process end log:
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited(v=vs.110).aspx
The Exited event indicates that the associated process exited. This occurrence means either that the process terminated (aborted) or successfully closed. This event can occur only if the value of the
EnableRaisingEvents property is
true.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • ColdFusion 9 Application Server windows service not being created

    I've done multiple installs of CF9, both 32 and 64-bit versions, on Windows 2003 servers and the ColdFusion 9 Application Server windows service isn't being displayed in the Services console.  If I go into the registry under HKLM\System\CCS\Services - I see the key for CF9 App Server was created, but "Description" is the only subkey value that was created.  The .Net Service, ODBC Server, Search Server, Solr Service windows services are being fully created properly.
    Can anyone shed some light on why the Application Server service isn't getting registered properly and any possible fixes?
    TIA

    fargo75 wrote: Can anyone shed some light on why the Application Server service isn't getting registered properly and any possible fixes?
    TIA
    Did you check out the ColdFusion Installation Log for any relevant failures?
    Any possible firewall or security settings not allowing the ColdFusion installer creating what it needs to create?

  • How to log in to Service Desk to create sample message to SAP?

    Dear all,
    How to log in to Service Desk under my Solution Manager server to create sample message to SAP under Component: SV-SMG-SUP?
    Regards
    GN

    Hi GN,
    You have different options to create messages in test component SV-SMG-SUP-TST:
    1. if you are on 7.1 you can create message using CRM_UI
    2. If you are using lower vrsion then either you can create message using Workcenter or using transaction NOTIF_CREATE or using menu --> Help --> Create support message.
    Thanks
    Regards,
    Vikram

  • Windows service does not stop when DB is shutdown from SQL*Plus

    I have a 11g XE DB in a Windows 7 machine.
    The installation has created a Windows service called OracleServiceXE. It's status is STARTED.
    I then login to SQLPLUS as sysdba and do a shutdown immediate;
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    Problem is, when I refresh the services, the OracleServiceXE is still showing as STARTED.
    If I use the listener control to stop the listener the Windows service OracleXETNSListener changes status to BLANK.
    Why is this?

    tvCa-Oracle wrote:
    That service is a prerequisite Windows service to be able to start the database, but it is not the status of the database itself.
    When you do start the database, he may or may not start the service automatically (not sure there), but it is a needed service, for each database SID, on Windows.
    If you want to know what it is, open Task Manager or Process Explorer, only start the service (not the database), and see which OS process is launched.
    AFAIK, this is only on Windows, there's no comparable component on Linux/Unix for this.
    The Windows service OracleServiceXE has c:\app\oracle\product\11.2.0\server\bin\ORACLE.EXE XE as the Parth to executable.
    If I click on the Services tab in Task manager, then right-click the OracleServiceXE and click Go to process, it show the oracle.exe in the processes tab.
    If stop it, the service, from the Windows service control, the oracle.exe disappears and we cannot login to the DB.
    If we start the service from the windows service control, the oradim.exe appears, then a second later the oracle.exe appears. Once the DB status of the Windows service is STARTED, the oradim.exe disappears.
    So, I can start and stop the oracle DB with the Windows service. But If I stop the DB from sql*plus the the service is not stopped....

  • How to move existing windows service to cloud?

    Hello team,
    We have one windows service.
    We call it as Monitor Service. This service is running at customer premise and continuously monitor the door controllers fixed at client location. it also update the database in case of any update observed at door control panel. My question is, This Window
    Service is separately running for each customer within their premise to monitor the devices fixed at customer location. How can I move this windows service to cloud (as without VM) such that it will monitor the multiple devices of more than one customers across
    the globe.  if it is not feasible then let us know any other alternate solution. Actually, this is a very grey area for us.
    Thanks,
    Bhavin Modi

    Hi,
    Here are a few key things which you might want to consider while planning your migration to Azure
    https://msdn.microsoft.com/en-us/library/azure/jj156157.aspx?f=255&MSPPError=-2147217396
    Azure provides different hosting models for running applications. Each one provides a different set of services, and so which one you choose depends on exactly what you're trying to do. You may choose any of the below offerings
    Cloud Service (PaaS)
    Virtual Machine (IaaS)
    Websites
    I suggest you to refer to the below article to find the best hosting model per your requirement
    http://azure.microsoft.com/en-us/documentation/articles/fundamentals-application-models/
    Hope this helps !
    Regards,
    Sowmya

  • Windows service start and stop automatically

    i'm trying to start windows service, which i installed via running beasvc with parameters. everything used to work fine, but yesterday somthing broke up: i press the start button in the control panel, service tries to start, but then it stops and the following message appears: "Weblogic 9.0 Workspace Service service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service." sometimes it stops right after starting without giving any messages.
    any ideas what's wrong with it&

    If I run from a cmd box it shows a successful start, however when I look at the services through the MMC it is not started. Basically, it starts successfully and then immediately shuts off stating the message in the original post. This is after and only after I apply sp7 for BEA 7. If I roll the server back to just v 7, I don't have a problem. I have downloaded V7 twice, and I get the same result. I have followed the install instructions to a T and still the same result. I have also tested removing the user created pages, and I get the same exact error telling me either it's a generic error or, SP7 has issues. The only reason we are rolling to SP7 is because of a security issue, but for the time being we have locked down the firewall. Any other suggestions? I have had my Maximo Administrator contact BEA, and MRO about this problem (Maximo is the only system we use web logic for) and they default to the answer that it is a java issue. That V7 is not supported above java 1.3.xxx which is bull because we were running version 1.4, due to a security issue with JVM 1.3 and all worked well. I have replicated the install with JVM 1.3xxx for BEA 7 sp 7, and that did not solve the problem either. Sorry for the long post I just wanted to try to get all the info out.
    Thank you for you time and consideration
    Tanner

  • Windows service entered the stopped state

    hello,
    my windows service running on Windows Server 2008 R2 SP1 stopps two or three times per month undefined with the Event ID 7036 : service entered the stopped state. 10 mins later it starts again alone: service entered the running state.
    What I also see is that some other services enter in the stopped state and then enter the running state: with Event ID 7036, but more frequently, means several times per day:
    SoftwareProtectionService
    WindowsModuleInstaller
    ApplicationExperience
    WMI Performance Adapter
    Portable Device Enumerator Service
    What is the problem here, I could not find any solution yet.
    thx

    Hi,
    Sometimes services are started only when they are needed. Most services you listed are Manual in startup type which means they will be started manually when it is needed. 
    Also if you disable a service manually, dependency services will also be stopped. 
    Here are 2 threads which mentioned 2 services in your list and they are also start/stop even 10 minutes. 
    Windows Modules Installer Stops & Restarts Frequently
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/d8e192ed-92ff-451b-9646-add8214c4e84/windows-modules-installer-stops-restarts-frequently
    7036 - Service entered the stopped/started state Messages
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/8360b321-8225-42f1-a3e8-a75020dad227/7036-service-entered-the-stoppedstarted-state-messages

  • Windows service on 10.5.8 server

    Just went to turn on Windows service in Server Admin on a 10.5.8 server....Did not see a the Windows service as it appears on my other 10.3 and 10.4 servers...Does SMB replace this service?

    SMB and CIFS and Samba are all names associated with network disk services used with Microsoft Windows platforms, yes.

  • How to setup the FTP Service by the OS X Server? Thanks~

    Dear All,
    OS X 10.8.2
    I want to setup a FTP Service by the "OS X Server".
    When I start the FTP Service, I can't login by my account.
    FTP Service and FTP Client run at the same computer,
    I think it's not the network problem.
    Do you have the documents about the FTP Setting or "OS X Server" User Guide?
    Thanks
    Austin

    service generally manages the lower level services on the system.
    High level services such as Apache are managed via serveradmin:
    serveradmin status web
    serveradmin start web

  • How to know when Windows support files are updated?  (BC 4)

    I have MacBook Pro Retina w/Lion (of course), installed Win 7 Pro 64-bit, using Boot Camp procedures and files that were issued June 14.  My BootCamp Assistant says it's 4.0.4.
    My question is:  how do I know when the Windows Support files (drivers) are updated by Apple?  I would have expected an update by now, but I just went into Boot Camp Assistant on Lion, re-downloaded the drivers, and I *think* they are all dated June 14th still.  (looked in WindowsSupport folder which is where it said it downloaded them)
    There doesn't seem to be a reasonable way to get notified if there are new drivers or not.
    My expectation was that I could run *something* either on the Windows or OS X side, and it would *tell me* that drivers needed updating, or at least say "you are running version X".
    It can't be that I have to re-download the drivers and check the dates on all the files every time I'm curious if there's updates available.  Can it?
    The files seem to be on some mysterious Apple server and the only thing I can do to that server is ask to download the support files.  No query, no "is an update available", ... ???
    It's not even clear to me that the Windows Support files have a version number. 

    When the next revsion of OS X you can run Boot Camp Assistant again, or of course once 10.8 though might want to just sit tight, you would likely see reports in forums and elsewhere.
    Apple Software Update for Windows use to but no longer.
    The easiest way to see device driver version, chipset and more is with AIDA64
    http://www.aida64.com/product/aida64-extreme-edition/overview

  • How to avoid, when Windows is natively started, to see the Mac Hc as resour

    Hi there!
    I have just bought a brand new iMac 21.5''
    Unfortunately, I need a Windows partition for some programs.
    I just installed Windows XP via Boot Camp and thing seemed to go good.
    But there's still a big problem: when I start Windows at the very start, in my resources I can see Mac's hard disk, and it is fully explorable (in read only mode, but it's still a problem), without entering any password.
    In my Mac hard disk all Users accesse are protected by password, but passwords entering can be easily avoided by accessing with the Windows partition.
    The point is :
    how to make Mac partition unexplorable from Windows OS?
    Thank you very much guys

    This one?
    <quote>
    I just found this:
    <---------------This is for bootcamp 3.0 users------------------------>
    By doing the following you will disable HFS mount / read mode on windows XP, Vista, 7.
    Navigate to c:/windows/systems32/drivers/AppleMNT.sys, rename the AppleMNT.sys file to something like AppleMNT_keep.sys or something of your likings.
    Reboot your machine and notice that your Mac volume is no longer mounted.
    </quote>
    Tonight I will try this patch and will post its functionality. It's still a very bad turnaround in my opinion, but if it's work it's good enough
    Thank you very much
    Please Apple provide an option inside BootCamp to allow / disallow this feature!
    Message was edited by: EtHeReAlStReAm

  • How to choose when windows updates are installed

    On previous versions of Windows I always used to set updates to be installed on a Monday, 6 days after Patch Tuesday, allowing enough time for any buggy updates to get redacted so I didn't end up with a bricked system.
    I cannot find how to do this on Winodws 8.1, there doesn't seem to be any option to choose when updates are installed.
    Snake

    Hi,
    You can control the schedule behavior via group policy, run gpedit.msc to launch the group policy editor
    Computer Configuration\Administrative Templates\Windows Components\Windows Update\Configure Automatic Updates, then change the options as you want
    after that, run gpupdate /force to update the policy
    Yolanda Zhu
    TechNet Community Support

  • How to log when a menu option is selected in an IVR Script

    Our business would like to track how many customers select a specific option in the menu of a CCX script.  For example: Customer calls in to the IVR and selects option 2 for a password reset within the menu.  My question is how to configure this within the script?
    We are running UCCX 8.0.
    Any help would be appreciated, thank you.

    The other thing we sometimes will do is to actually create a queue with no agents in it.  Queue the call and then dequeue the call, and you will be able to run reports on that queue to see how many calls went into it.  It's a workaround, but is sometimes easier for customers in smaller environments especially.
    John Irey
    Tympani Inc.

  • How to get the Windows service

    Hi friends,
    I can able to get My system ip address using InetAddress.But i need to get what are all services is going in particular ip address.
    Is it possible in java.If possible then can u send me the code for the same.
    import java.io.*;
    import java.net.*;
    public class IPaddresses
    public static void main(String args[])
    try
    System.out.println("local IP address " + InetAddress.getLocalHost().toString());
    catch (Exception se) {System.err.println("error " + se); }
    Thanks & Regards,
    Yousuf .

    yousufalam wrote:
    Hi friends,
    I can able to get My system ip address using InetAddress.But i need to get what are all services is going in particular ip address.
    Is it possible in java.No.

  • How to tell when controls are finished being created?

    I am building an application that constructs the main user interface dynamically, based on XML parameters gathered from a database. There are more than 130 components in the UI, including the layout containers and formitems.
    At the beginning of the function that creates all the controls, I capture the time, with microseconds. At the end of that function, I do it again. Typically it takes about 3 seconds to run that function.
    However... the UI doesn't appear then. Flash's "busy" cursor keeps spinning away for another 7 to 10 seconds before the UI actually appears. I need to be able to give the user some real feedback about progress. Is there any way to keep track of things more accurately?
    Thanks.
    Paul

    These links could help you:
    http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_03.html
    http://flexcomps.wordpress.com/2008/05/09/flex-component-life-cycle/

Maybe you are looking for

  • How to call the data from BW to R/3

    HI everybody, I am having one /BIC/OHZSDS_QCAL in the BW which is created by the BW consultant, this /BIC/OHZSDS_QCAL consist of data in it now i have to call this R/3 and create a report to display. i am not getting any idea how to call this /BIC/OH

  • 5/28/2014 - Beta - Flash Player 14.0.0.122

    The latest Flash Player 14 builds are now available.  You can download Flash Player here: http://www.adobe.com/go/flashplayerbeta. New Features for Flash Player 14: PPAPI Content Debugger - EXTENDED BETA We're pleased to announce the immediate availa

  • Aperture 3 and GPS logs

    According to the manual, Aperture 3 can place photos on a map based on camera GPS data, or else manually by clicking on a map. I have a camera that doesn't support GPS and was hoping I could find a solution where Aperture can add GPS EXIF data based

  • TS1717 Im new to itunes so this might be a simple answer but...

    Im new to itunes so this might be a simple answer but...I downloaded 20 songs a few days ago and the last 45-60 second ds of more than half didn't download. When playing the song it will kirt move to the next song. How can I get it to download again

  • Help needed with multiple and seperate image galleries on 1 site

    I'm looking for a simple way to create and manage multiple image galleries (about 100) on a single website. I work for an architect and have a site which has our project portfolio and every project has a page containing a write up with a gallery of o