private void EmitEvent(StatsTrackerEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<StatsTrackerEventArgs> handler = Changed;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #2
0
        static void StatsTrackerChangedHandler(object source, StatsTrackerEventArgs e)
        {
            WebClient client = new WebClient();
            client.Headers.Add("Authorization", "Token " + key);
            client.Headers.Add("Content-Type", "application/json");

            try
            {
                var response = client.UploadString(TrackerUriMap[source.GetType()], serializer.Serialize(source));
                Console.WriteLine(response);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error: {0}, params: {1}", exception.Message, serializer.Serialize(source));
            }
        }