Windows service get stuck and spike cpu usage on calling FOCAS cnc_allclibhndl3 funct
Hi to everybody!
I made a windows service that each 5 second call the cnc_allclibhndl3 function to get the handle, then call cnc_statinfo/cnc_rddynamic2/cnc_rdsvmeter/cnc_rdspmeter/cnc_sysinfo/cnc_rdparar/cnc_rdalmmsg2, finally release the handle with cnc_freelibhndl.
After running fine for 2-3 hours I notice from the task manager that the service show 100% cpu using.
From the log I can see that the service is stuck on calling the cnc_allclibhndl3 function.
Restarting the service solve the problem for the next 2-3 hours.
The service it's write in C#.
Re: Windows service get stuck and spike cpu usage on calling FOCAS cnc_allclibhndl3 f
I have a follow up on this, I changed the service to leave the handle open until the end of the program or an error from an api call occurred.
Now the service it's stable and it's up and running from some days but I notice a lot of errors on the log calling cnc_statinfo that return -8 "Windows library handle error"
Each time that cnc_statinfo return this error I call cnc_freelibhndl to release the current handle and then cnc_allclibhndl3 to get a new one. With the new handle I can successfully call cnc_statinfo for 2-3 times, with a delay of 5 seconds between each, before I get a -8 error again.
Re: Windows service get stuck and spike cpu usage on calling FOCAS cnc_allclibhndl3 f
fabriziocs,
Have you tried varying the "timeout" in your handle call?
cnc_allclibhndl3( "IP ADDRESS", 8193, 10, &h ) --- in this case it's 10 seconds -----
timeout [ in ]
Specify seconds for timeout. If specify 0, timeout process is ignored and the library functions wait infinity.
The best timeout value is different according as system. For example, in case of the hi-speed network system, 10 seconds is sufficient for timeout. But in case of relaying by low-speed telephone line, more than 60 seconds is well for timeout.So you must specify the timeout value after the measurement of your communication time.
Re: Windows service get stuck and spike cpu usage on calling FOCAS cnc_allclibhndl3 f
Hi freakycnc,
I'm going to increasing the timeout from 6 to 10 seconds, even if the error is returned from the cnc_statinfo and looking at the trace log the -8 error is returned in less than a second after the function call.
The system is on a hi-speed network.
Re: Windows service get stuck and spike cpu usage on calling FOCAS cnc_allclibhndl3 f
Just in case someone else runs into this issue in the future.... A fanuc handle is only good on the thread in which it is called. So if you are using a timer, task, backgroundworker, etc.... then you are going to run into the -8 error. using something like a timer results in C# grabbing a thread from the thread pool, so every time it elapses it could potentially execute on a different thread which will invalidate your fanuc handle. The way around this is to make the Focas calls in a loop.
If anyone is looking for Focas tutorials, I have a youtube channel and website you can check out.