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

Last change on this file since 3329 was 3329, checked in by mkommend, 12 years ago

added ViewHost in ExperimentView for the RunCollection and implemented IStringConvertibleMatrix in RunCollection (ticket #970)

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