It could be your fan, but there's something I need you to confirm...
When you say that the fan stops but your computer is still on, do you mean that the fan never works or do you mean that when you experience a loss of signal it's only your fan that stops?
What's most likely is that because the fan isn't working the CPU is overheating and is shutting down as a safety mechanism. This would manifest itself via the fan not working at all / intermittently and after a period of running your PC shuts itself down.
This is something you could do yourself by checking your PC technical specification and buying the right fan, alternatively a PC repair shop could do this for you.