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 | /// <summary>
|
---|
19 | /// Asynchronous call of GUI updating.
|
---|
20 | /// </summary>
|
---|
21 | /// <param name="method">The delegate to invoke.</param>
|
---|
22 | protected new void Invoke(Delegate method) {
|
---|
23 | // prevents blocking of worker thread in Invoke, if the control is disposed
|
---|
24 | IAsyncResult result = BeginInvoke(method);
|
---|
25 | result.AsyncWaitHandle.WaitOne(1000, false);
|
---|
26 | if (result.IsCompleted) try { EndInvoke(result); }
|
---|
27 | catch (ObjectDisposedException) { } else {
|
---|
28 | ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
|
---|
29 | new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
|
---|
30 | null, -1, true);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | /// <summary>
|
---|
35 | /// Asynchronous call of GUI updating.
|
---|
36 | /// </summary>
|
---|
37 | /// <param name="method">The delegate to invoke.</param>
|
---|
38 | /// <param name="args">The invoke arguments.</param>
|
---|
39 | protected new void Invoke(Delegate method, params object[] args) {
|
---|
40 | // prevents blocking of worker thread in Invoke, if the control is disposed
|
---|
41 | IAsyncResult result = BeginInvoke(method, args);
|
---|
42 | result.AsyncWaitHandle.WaitOne(1000, false);
|
---|
43 | if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
|
---|
44 | else {
|
---|
45 | ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
|
---|
46 | new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
|
---|
47 | null, -1, true);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|