C # how to handle internet breaks

My program downloads data from the server, as soon as it has received all the data, my program processes the data (checks, for example, if this data is still on the server) and saves it in my database.

Now I was wondering what if my Internet connection suddenly disconnects, what happens to the data that I just received. So I did a test. When I break the Internet connection, my program stops receiving data and goes to my method for checking data.

Now this is wrong, because it will install some data already in my database, that it is no longer on the server, when it really is.

Access to the server is through the API (web services).

So my question is a good way to handle this situation?

+3
source share
2 answers

Have you tried to catch a WebException and handle it accordingly?

+4
source

You need to find a way to determine if all data has been transmitted. Either the type of sequence at the end of the file in the data, or you have a command that tells you how much data needs to be loaded before the data is loaded. This way, you can check if the connection is broken (i.e., stop receiving data) if you received everything that you needed.

+1
source

Source: https://habr.com/ru/post/1721785/


All Articles