Click here to Skip to main content
Click here to Skip to main content

Event traffic calming

By , 26 Jan 2013
 
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

using SampleDomain;
using TrafficCalming;

namespace RealTimeClient
{
    public partial class MainForm : Form
    {
        private readonly OrderRepository _ordersRepository = new OrderRepository();
        
        private DateTime _lastTimeUpdatedAt = DateTime.MinValue;
        
        public MainForm()
        {
            InitializeComponent();
            
            _ordersRepository.OrderArrived += HandleOrderArrived;
        }        
        
        private void HandleOrderArrived(object sender, EventArgs e)
        {
            if (Handle == IntPtr.Zero)
                return;
                
            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)
        {
            _ordersRepository.StartGenerating();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of use 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.

License

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

About the Author

Erich Ledesma
Software Developer Babtec Informationssysteme GmbH
Spain Spain
Member
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.
 
Programming Languages I use:
C#, C++, Javascript, Delphi, Java, PHP, and others (less frequently).

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