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
And this is my Dowork that he runs
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.
– user178974
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.
– Pedro Filipe
+/- 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.
– user178974
If your interaction with the bank takes too long, you should segment the interaction and do it by parts/Hunks.
– user178974