Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way to solve this problem would be to use a polling mechanism. This can be plumbed in using the <a href="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx" rel="nofollow">System.Threading.Timer</a>, which uses the System.Threading.ThreadPool. </p> <p>You would repeatedly query to see if your data has been updated. You'll need to store the modified date with your data, I'd recommend storing it in UTC. Alternatively, you could just use an integer tag that is incremented every time data is updated, then if the tag is out of date, you know you need to update your displayed data.</p> <p>The dangerous thing about polling refreshes is how much load your server will encounter, but if your concurrent user base is small, this will not be a problem. If you find it causes performance problems, you can adjust your polling interval, incorporate caching techniques, and possibly farm your server(s).</p> <p>Your new OrderView class will probably look similar to the following:</p> <pre><code>using System.Windows.Forms; using Demo.Model; using System.Threading; namespace Demo.Controls { public partial class OrderView : UserControl, IDisposable { private Order _order; private Timer poller; public Order Order { get { return _order; } set { _order = value; UpdateView(); } } private void UpdateView() { if (_order == null) return; IdLBL.Text = string.Format("ID: {0}", _order.Id); DateLBL.Text = string.Format("Date: {0}", _order.Date); ItemsDGV.DataSource = _order.Items; } public OrderView() { InitializeComponent(); _poller = new Timer(CheckUpdate, null, timeSpan, timeSpan); } private void CheckUpdate(Object state) { //Do update check and update Order if it has changed } public void Dispose() { if (_poller != null) { _poller.Dispose(); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload