I don't think time sleeps work in the main thread (anything in the ui) because this is the main thread, and all ui everything stops until your function returns.
it would be helpful to see actual code, but at least describe the structure/functions of how messages are being sent/received, and from what functions and threads.