Synchronising data in C# We use a third party dll which has an object called CServer and was provided by one of our software vendors to act as an API between our applications and their applications.

CServer has the following method: 

bool SynchroniseData() which can be called if we want to fetch data from server which is very important for our application. This call signifies to the DLL our intention that we want to fetch the data. It does not fetch the data. Instead it returns true, if the request was successfully send to their application.

When data are actually fetched in the CServer object, CServer fires the event onDataFetched. We listen to that event and process the data. The CServer always has the latest data, since it continuously synchronises the data with our Vendor's servers.

However, there are many times at which the event onDataSynchronisationStopped is called. This signifies that the CServer object will stop data synchronisation with the server. This event is fired when the network is momentarily down, or if the server has some minor delays and so on.

We always want to have that data, and thus we try to fetch them again.

We currently do it like this:

private void OnDataFetchedHandler(object sender, EventArgs eventArgs){

            try{
                bool dataHaveBeenFetched;
                do{
                    dataHaveBeenFetched = TrytoFetchData((CServer) sender);
                    Thread.Sleep(1000);
                } while (!dataHaveBeenFetched);
            }
            catch (Exception ex){
                Log.ErrorFormat(ex.Message, ex);
            }
        }

        private bool TrytoFetchData(CServer sender){
            sender.SynchroniseData();
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            EventHandler manualResetEventSethandler = (s, e) =&gt; manualResetEvent.Set();
            sender.OnDataFetched += manualResetEventSethandler;

            bool dataHaveBeenFetched = manualResetEvent.WaitOne(new TimeSpan(0, 0, 3, 0));
            sender.OnDataFetched -= manualResetEventSethandler;

            return dataHaveBeenFetched;
        }


Is there any cleaner way of doing this?
Instead of do ... while loop you can use SpinWait.SpinUntil:

bool dataHaveBeenFetched = SpinWait.SpinUntil(() =&gt; TrytoFetchData((CServer)sender))


And as @t3chb0t noted it seems strange to sleep 1 second between TrytoFetchData calls.