Click to See Complete Forum and Search --> : C# windows Service problems


Waqas_Badar
February 7th, 2008, 04:54 AM
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?

Tischnoetentoet
February 7th, 2008, 05:38 AM
Probably, the start function in your services throws an exception. Did you use a try...catch mechanism to catch any errors?

Arjay
February 7th, 2008, 12:34 PM
Along with a try/catch block, you can use the ServiceBase.EventLog (http://msdn2.microsoft.com/en-us/library/system.serviceprocess.servicebase.eventlog(VS.80).aspx) property to write the error(s) to the event log.

chinnaraj
February 7th, 2008, 11:58 PM
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

Waqas_Badar
February 8th, 2008, 01:02 AM
i have put try cath in start method but nothing is written in event log.
ANY OTHER CLUE TO RESOLVE THIS ISSUE?

Tischnoetentoet
February 8th, 2008, 01:32 AM
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).

Arjay
February 8th, 2008, 12:13 PM
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
ChinnaPlease post a separate question.

Arjay
February 8th, 2008, 12:18 PM
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....


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

Waqas_Badar
February 9th, 2008, 01:37 AM
I have written another simple window service. The code is as follows:

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:

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?

dglienna
February 9th, 2008, 02:03 AM
Post the code that you have, along with any error messages highlighted in RED

Waqas_Badar
February 9th, 2008, 02:12 AM
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.