- Are you closing the log file each time you write to it? If not, you might not see the most recent log event.
- You should be able to use the log file to follow what lines are executed in Receive, if not the debugger.
- If you want ot keep the loop running the longest, you should have a try, catch block just inside the while loop.
- This is a silly question, but are you sending the stop_app command and that is why the thread is only running once?
- You could try simplifying the code to identify the problem.