Hi Matthew,
Thanks for posting in the community.
First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to create a TCP/IP
server as an windows service.
Also you wants to monitor the service with an UI application(winform app)
and write to file. And you find the application will exaust all the CPU
when there is no active connection.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.
I agree with Glenn's suggestion that utilized the remoting the do the IPC
between the windows service and the monitor APP. You can also handle the
remoting object's event to achieve your aim.
How To: Host a Remote Object in a Windows Service
http://msdn.microsoft.com/library/de...us/dnnetsec/ht
ml/SecNetHT15.asp
Windows Service can access the file system, but you need to check if the
account you use the run the service has the permission to access to the log
file you want to write to.
As for the first question, I suggest you may check if there is any
difference between the code between console application and the windows
services. Usually a standard Server Socket application will suspend at a
line similar with below to wait for conncetion from client.
' Program is suspended while waiting for an incoming
connection.
Dim handler As Socket = listener.Accept()
Since your application is high CPU consumer when there is no client
connection, so you may try to debug into the windows service to see which
code line cause the high CPU time consumption.
To debug an windows service, you may need to attach vs.net debugger to a
running windows service
Debugging Windows Service Applications
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbtskdebuggingserviceapplications.asp
If you will accept multiple connections at one time in the services, I
think the Asynchronous invoking will be good pratices.
Asynchronous Server Socket Example
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconnon-blockingserversocketexample.asp
Asynchronous Client Socket Example
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconnon-blockingclientsocketexample.asp
If you have any concern on this issue, please post here.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.