-
February 7th, 2008, 05:54 AM
#1
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
-
February 7th, 2008, 06:38 AM
#2
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?
-
February 7th, 2008, 01:34 PM
#3
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.
-
February 8th, 2008, 12:58 AM
#4
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
-
February 8th, 2008, 02:02 AM
#5
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
-
February 8th, 2008, 02:32 AM
#6
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).
-
February 8th, 2008, 01:13 PM
#7
Re: C# windows Service problems
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.
-
February 8th, 2008, 01:18 PM
#8
Re: C# windows Service problems
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 );
}
}
-
February 9th, 2008, 02:37 AM
#9
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
-
February 9th, 2008, 03:03 AM
#10
Re: C# windows Service problems
Post the code that you have, along with any error messages highlighted in RED
-
February 9th, 2008, 03:12 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|