CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2005
    Posts
    49

    C# windows Service problems

    I have written a window service in C#. On windows XP it runs fine. I checked it on my computer and some other computers in office. I am able to install it on production system. But when i try to run this service i receive following error:

    "ERROR 1053: The service did not respond to the start or control request in timely fashion"

    I google on this error. Most of people are saying that Start method of service should return as soon as possible. In my start method, i am opening a file, making a socket and creating and starting a thread.
    After this when i try to uninstall the service i got following error:

    Exception occurred while initializing the installation:
    System.BadImageFormatException: Could not load file or assembly 'file:///C:\game firewall\New Folder (4)\Firewall.exe' or one of its dependencies. The module was expected to contain an assembly manifest..

    ANY BODY COULD TELL ME TO RESOLVE THAT PROBLEM?
    Muhammad Waqas Badar

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: C# windows Service problems

    Probably, the start function in your services throws an exception. Did you use a try...catch mechanism to catch any errors?

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# windows Service problems

    Along with a try/catch block, you can use the ServiceBase.EventLog property to write the error(s) to the event log.

  4. #4
    Join Date
    Jan 2008
    Posts
    45

    C# windows Service problems

    Hi,
    I m very new to C# .net.
    I have created the windows forms. And also having the link to go for different forms.
    But I m facing a prob. , When I go to second form then again If I want to go to first form then It will reopen (again open a new form) that form .
    But I want that, whem I want to go for first form then it should redirect the first form, Not should open it again.


    Please Reply Soon
    Chinna

  5. #5
    Join Date
    Nov 2005
    Posts
    49

    Re: C# windows Service problems

    i have put try cath in start method but nothing is written in event log.
    ANY OTHER CLUE TO RESOLVE THIS ISSUE?
    Muhammad Waqas Badar

  6. #6
    Join Date
    Nov 2003
    Posts
    2,185

    Re: C# windows Service problems

    Of course it's not written to the event log automatically, you will have to write log messages to the event log manually.

    Is the user starting (running) the service an administrator? For example, maybe you have a deadlock (waiting for a file to be created or something like that).

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# windows Service problems

    Quote Originally Posted by chinnaraj
    Hi,
    I m very new to C# .net.
    I have created the windows forms. And also having the link to go for different forms.
    But I m facing a prob. , When I go to second form then again If I want to go to first form then It will reopen (again open a new form) that form .
    But I want that, whem I want to go for first form then it should redirect the first form, Not should open it again.


    Please Reply Soon
    Chinna
    Please post a separate question.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# windows Service problems

    Quote Originally Posted by Waqas_Badar
    i have put try cath in start method but nothing is written in event log.
    ANY OTHER CLUE TO RESOLVE THIS ISSUE?
    In its most simplest form....

    Code:
    protected override void OnStart( string[ ] args )
    {
      try
      {
        // Put your OnStart code here
      }
      catch( Exception ex )
      {
        EventLog.WriteEntry( ex.Message , EventLogEntryType.Error );
      }
    }

  9. #9
    Join Date
    Nov 2005
    Posts
    49

    Re: C# windows Service problems

    I have written another simple window service. The code is as follows:
    Code:
    namespace WindowsService3
    {
        public partial class Service1 : ServiceBase
        {
            public Service1()
            {
                try
                {
                    InitializeComponent();
                    this.ServiceName = "testService";
                    this.EventLog.Log = "Application";
    
                    // These Flags set whether or not to handle that specific
                    //  type of event. Set to true if you need it, false otherwise.
                    this.CanHandlePowerEvent = true;
                    this.CanHandleSessionChangeEvent = true;
                    this.CanPauseAndContinue = true;
                    this.CanShutdown = true;
                    this.CanStop = true;
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("test service", ex.Message, EventLogEntryType.Error);
                }
            }
    
            protected override void OnStart(string[] args)
            {
                // TODO: Add code here to start your service.            
                try
                {
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("test service", ex.Message, EventLogEntryType.Error);
                }
    
            }
    
            protected override void OnStop()
            {
                // TODO: Add code here to perform any tear-down necessary to stop your service.
            }
        }
    }
    And its installer class contain following code:
    Code:
    namespace WindowsService3
    {
        [RunInstaller(true)]
        public partial class Installer1 : Installer
        {
            public Installer1()
            {
                InitializeComponent();
    
                ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
                ServiceInstaller serviceInstaller = new ServiceInstaller();
    
                //# Service Account Information
                serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
                serviceProcessInstaller.Username = null;
                serviceProcessInstaller.Password = null;
    
                //# Service Information
                serviceInstaller.DisplayName = "test service";
                serviceInstaller.Description = "Service collect information like current map, mod, players info etc.";
                serviceInstaller.StartType = ServiceStartMode.Automatic;
    
                // This must be identical to the WindowsService.ServiceBase name
                // set in the constructor of WindowsService.cs
                serviceInstaller.ServiceName = "testService";
    
                this.Installers.Add(serviceProcessInstaller);
                this.Installers.Add(serviceInstaller);
            }
        }
    }
    I try to run that service, but same issue rises.
    On production system, windows 2003 R2 is installed. Is that issue with OS?
    Last edited by Waqas_Badar; February 9th, 2008 at 03:05 AM. Reason: Code added
    Muhammad Waqas Badar

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: C# windows Service problems

    Post the code that you have, along with any error messages highlighted in RED
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Nov 2005
    Posts
    49

    Re: C# windows Service problems

    i have posted the code. See, one thread above. On run following error is return:

    "ERROR 1053: The service did not respond to the start or control request in timely fashion"


    And on uninstall, it gives following error:

    "Exception occurred while initializing the installation:
    System.BadImageFormatException: Could not load file or assembly 'file:///C:\game firewall\New Folder (4)\Firewall.exe' or one of its dependencies. The module was expected to contain an assembly manifest..
    "

    I am unable to color it red. I try font tag but it is not working.
    Muhammad Waqas Badar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured