Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/AsynchronousContentView.cs @ 3484

Last change on this file since 3484 was 3416, checked in by mkommend, 15 years ago

implemented ContentViews and propagation of view state changes (ticket #982)

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Threading;
10using HeuristicLab.Common;
11
12namespace HeuristicLab.MainForm.WindowsForms {
13  public partial class AsynchronousContentView : ContentView {
14    public AsynchronousContentView() {
15      InitializeComponent();
16    }
17
18    public AsynchronousContentView(IContent content)
19      : this() {
20      this.Content = content;
21    }
22
23    /// <summary>
24    /// Asynchronous call of GUI updating.
25    /// </summary>
26    /// <param name="method">The delegate to invoke.</param>
27    protected new void Invoke(Delegate method) {
28      // prevents blocking of worker thread in Invoke, if the control is disposed
29      IAsyncResult result = BeginInvoke(method);
30      result.AsyncWaitHandle.WaitOne(1000, false);
31      if (result.IsCompleted) try { EndInvoke(result); }
32        catch (ObjectDisposedException) { } else {
33        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
34          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
35          null, -1, true);
36      }
37    }
38
39    /// <summary>
40    /// Asynchronous call of GUI updating.
41    /// </summary>
42    /// <param name="method">The delegate to invoke.</param>
43    /// <param name="args">The invoke arguments.</param>
44    protected new void Invoke(Delegate method, params object[] args) {
45      // prevents blocking of worker thread in Invoke, if the control is disposed
46      IAsyncResult result = BeginInvoke(method, args);
47      result.AsyncWaitHandle.WaitOne(1000, false);
48      if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
49      else {
50        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
51          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
52          null, -1, true);
53      }
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.