strange problem with API c# class MK-stuck

hello ,
I’m running a C# application that connect to the mikrotik using api
I have notice that some time my application “freeze” without any explain
when I debug the code I can see it get stuck here :

while (true)
{
try
{
tmp[3] = (byte)connection.ReadyByte(); /// -> the code stuck here 

catch (Execption e)
{
Console.WriteLine(e);
}

finally 
{}

}


}

any idea why ?

can it be that while entering and getting data from the router , the router is turn off? or lose connection?

how can I overcome this problem - if this is the case?


**
I have notice its happnd when I lose connection to the router while reading information from him
so where do I need to put try\catch in order to make him stop and go to the next one of the list ?


Thanks ,