dotnet / windows-sdk-for-google-analytics

SDK to connect to Google Analytics from Windows Store (UWP) Apps, Windows desktop apps written with .NET, and Xamarin Apps
MIT License
102 stars 33 forks source link

BUG. Hits queue isn't clearing in DispatchAsync(). #31

Open 23W opened 7 years ago

23W commented 7 years ago

If TrackerManager.DispatchPeriod is set in non zero value, for example 10 seconds, then all hits that were collected from application startup time will be sent every 10 seconds. This is because DispatchAsync() method doesn't clear hits queue for hits that are sent. Current method's code should be changed to :

        public async Task DispatchAsync()
        {
            if (!isEnabled) return;

            Task allDispatchingTasks = null;
            lock (dispatchingTasks)
            {
                if (dispatchingTasks.Any())
                {
                    allDispatchingTasks = Task.WhenAll(dispatchingTasks);
                }
            }
            if (allDispatchingTasks != null)
            {
                await allDispatchingTasks;
            }

            if (!isEnabled) return;

            Hit[] hitsToSend;
            lock (hits)
            {
                hitsToSend = hits.ToArray();
                hits.Clear(); // clear queue.
            }
            if (hitsToSend.Any())
            {
                await RunDispatchingTask(DispatchQueuedHits(hitsToSend));
            }
        }

Please, fix library.

23W commented 7 years ago

Hey! Will anybody fix this issue?