c# winform locking when network drops

Asked

Viewed 42 times

0

I have a windows form system that needs a loop check all the time. The problem that is happening is that when the network falls and this loop tries to connect in the database the screen gets stuck, and sometimes the user even has to close the system.

In my Form_load() I installed a backgroundWorker inserir a descrição da imagem aqui

And this is my Dowork that he runs inserir a descrição da imagem aqui

the main logic occurs in this load(), where it accesses the database several times in its cycle. Within this method, every call to Treadh UI components I make using Begininvoke, without invoking the whole form to avoid problem.

I do not know if I could structure differently this and neither the point at which this bottleneck is occurring when the network falls.

  • Dealing with disconnections involves doing a Polling (constant query) on the network socket, but often the API does not expose the socket. There are several questions about this, the most practical way is to use transactions and a Try/catch block in network operations, in case of error you recover the previous state before trying a new connection.

  • Face that you said to recover the previous state before trying a new connection gave me an idea here that I had not thought of. If it once fell in the catch at the time of opening the connection, I can save that state and make q this state activate the network check, when the network comes back I update that state and unlock the input to open the connection in the methods again.

  • +/- that. The default is: Start a connection, prepare the SQL commands and the data to be transimitods, start a transaction, do all the work in a single connection, finally if everything goes well, confirm the transaction with "COMMIT" in the database. The bank will only change if you call the transaction commit. In your client application you place the interaction block with the bank within a Try/catch, pay attention to the details of the type of error that occurs so you can handle the different errors. If everything happens well in the interaction with the bank you update the client.

  • If your interaction with the bank takes too long, you should segment the interaction and do it by parts/Hunks.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.