Hello!
Below I have the two methods OnStart and Start that are relevant to my
question.
If I do net start TimeServerServi ce I will see something like Service
TimeServerServi ce starting .........
It wasn't possible to start the service TimeServerServi ce
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(thi s.Start));
t.Start();
but when I compile I get this error message
Could not copy temporary files to the output directory.
The file 'TimeService.ex e' 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.pd b' 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.S tart();
Socket s;
Byte[] incomingBuffer;
Byte[] time;
int bytesRead;
while (!this.isStoppe d)
{
s = this.listener.A cceptSocket();
incomingBuffer = new Byte[100];
bytesRead = s.Receive(incom ingBuffer);
time = Encoding.ASCII. GetBytes(
System.DateTime .Now.ToString() .ToCharArray()) ;
s.Send(time);
}
this.listener.S top();
}
//Tony