1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using System.Threading;
|
---|
10 | using HeuristicLab.Common;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|