Click here to Skip to main content
12,451,232 members (53,078 online)
Click here to Skip to main content

Tagged as


6 bookmarked

Event traffic calming

, 26 Jan 2013 CPOL
How to build an object to calm down event traffic.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

using SampleDomain;
using TrafficCalming;

namespace CalmedClient
    public partial class MainForm : Form
        private readonly OrderRepository _ordersRepository = new OrderRepository();
        private readonly EventCalmer _calmer = new EventCalmer(TimeSpan.FromSeconds(5));
        private DateTime _lastTimeUpdatedAt = DateTime.MinValue;
        public MainForm()
            _ordersRepository.OrderArrived += _calmer.HandleEvent;
            _calmer.EventOccurred += HandleOrderArrived;
        private void HandleOrderArrived(object sender, EventArgs e)
            if (Handle == IntPtr.Zero)
            this.Invoke(new Action(UpdateOrdersGrid));
        private void UpdateOrdersGrid()
            var orders = _ordersRepository.ListFrom(_lastTimeUpdatedAt).ToList();
            _ordersGrid.DataSource = orders ;
            _lastTimeUpdatedAt = DateTime.Now;
        private void MainFormLoad(object sender, System.EventArgs e)
        private void Button1Click(object sender, System.EventArgs e)
            MessageBox.Show(this, "Button clicked", "Info", 
                            MessageBoxButtons.OK, MessageBoxIcon.Information);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Erich Ledesma
Architect SunHotels
Spain Spain
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.

I mainly work in web applications using C# and some Javascript. Some very few times do some Java.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 26 Jan 2013
Article Copyright 2013 by Erich Ledesma
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid