About window service

T

TonyJ

Hello!

Below I have the two methods OnStart and Start that are relevant to my
question.
If I do net start TimeServerService I will see something like Service
TimeServerService starting .........
It wasn't possible to start the service TimeServerService
The reason for this it that OnStart doesn't return becuse it will stuck in a
loop in the
Start metod.

When this happened I go back to VS2005 and changed the code in OnStart to
this code
using a Thread instead
this.isStopped = false;
Thread t = new Thread(new ThreadStart(this.Start));
t.Start();

but when I compile I get this error message
Could not copy temporary files to the output directory.
The file 'TimeService.exe' cannot be copied to the run directory. Det går
inte att komma åt filen eftersom den
används av en annan process.
The file 'TimeService.pdb' cannot be copied to the run directory. Det går
inte att komma åt filen eftersom den
används av en annan process.

This text "Det går inte att komma åt filen eftersom den används av en annan
process" is in english something like
The file in not reachable because another process is using it.

I had to reboot before being able to compile my project.

When the Service OnStart doesn't return it seems to be a system process that
is holding it in some way according to the compile error.

How can I solve this problem without rebooting?


protected override void OnStart(string[] args)
{
isStopped = false;
Start();
}

public void Start()
{
this.listener.Start();

Socket s;
Byte[] incomingBuffer;
Byte[] time;
int bytesRead;

while (!this.isStopped)
{
s = this.listener.AcceptSocket();
incomingBuffer = new Byte[100];
bytesRead = s.Receive(incomingBuffer);

time = Encoding.ASCII.GetBytes(
System.DateTime.Now.ToString().ToCharArray());
s.Send(time);
}
this.listener.Stop();
}

//Tony
 
M

Mr. Arnold

but when I compile I get this error message
Could not copy temporary files to the output directory.

When the Service OnStart doesn't return it seems to be a system process
that
is holding it in some way according to the compile error.

How can I solve this problem without rebooting?

The exe is still holding on to resources and access is being denied to the
exe file so that it can be replaced with a new exe.

You should use the .Net InstallUtil (for .Net NT services) to uninstall the
service. You should be able to compile then to create the exe. But
sometimes, you got to boot the machine to get rid of the lockout on the exe,
if it has horribly aborted/terminated.
 
G

Guest

Tony,
Try using code like this which will run your service as an EXE in debug
mode without installing, and when compiled in release mode, you can install
as a service:

// The main entry point for the process
static void Main()
{
#if (!DEBUG)
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#else
// debug code: allows the process to run as a non-service
// will kick off the service start point, but never kill it
// shut down the debugger to exit
Service1 service = new Service1();
service.();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#endif
}

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



TonyJ said:
Hello!

Below I have the two methods OnStart and Start that are relevant to my
question.
If I do net start TimeServerService I will see something like Service
TimeServerService starting .........
It wasn't possible to start the service TimeServerService
The reason for this it that OnStart doesn't return becuse it will stuck in a
loop in the
Start metod.

When this happened I go back to VS2005 and changed the code in OnStart to
this code
using a Thread instead
this.isStopped = false;
Thread t = new Thread(new ThreadStart(this.Start));
t.Start();

but when I compile I get this error message
Could not copy temporary files to the output directory.
The file 'TimeService.exe' cannot be copied to the run directory. Det går
inte att komma åt filen eftersom den
används av en annan process.
The file 'TimeService.pdb' cannot be copied to the run directory. Det går
inte att komma åt filen eftersom den
används av en annan process.

This text "Det går inte att komma åt filen eftersom den används av en annan
process" is in english something like
The file in not reachable because another process is using it.

I had to reboot before being able to compile my project.

When the Service OnStart doesn't return it seems to be a system process that
is holding it in some way according to the compile error.

How can I solve this problem without rebooting?


protected override void OnStart(string[] args)
{
isStopped = false;
Start();
}

public void Start()
{
this.listener.Start();

Socket s;
Byte[] incomingBuffer;
Byte[] time;
int bytesRead;

while (!this.isStopped)
{
s = this.listener.AcceptSocket();
incomingBuffer = new Byte[100];
bytesRead = s.Receive(incomingBuffer);

time = Encoding.ASCII.GetBytes(
System.DateTime.Now.ToString().ToCharArray());
s.Send(time);
}
this.listener.Stop();
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top