[3227] | 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 |
|
---|
| 11 | namespace 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>
|
---|
[3229] | 23 | /// Asynchronous call of GUI updating.
|
---|
[3227] | 24 | /// </summary>
|
---|
| 25 | /// <param name="method">The delegate to invoke.</param>
|
---|
| 26 | protected new void Invoke(Delegate method) {
|
---|
[3329] | 27 | // prevents blocking of worker thread in Invoke, if the control is disposed
|
---|
| 28 | if (!IsHandleCreated)
|
---|
| 29 | return;
|
---|
[3250] | 30 | IAsyncResult result = BeginInvoke(method);
|
---|
| 31 | result.AsyncWaitHandle.WaitOne(1000, false);
|
---|
[3329] | 32 | if (result.IsCompleted) try { EndInvoke(result); }
|
---|
| 33 | catch (ObjectDisposedException) { } else {
|
---|
[3250] | 34 | ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
|
---|
[3266] | 35 | new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
|
---|
[3250] | 36 | null, -1, true);
|
---|
| 37 | }
|
---|
[3227] | 38 | }
|
---|
[3250] | 39 |
|
---|
[3227] | 40 | /// <summary>
|
---|
[3229] | 41 | /// Asynchronous call of GUI updating.
|
---|
[3227] | 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) {
|
---|
[3329] | 46 | // prevents blocking of worker thread in Invoke, if the control is disposed
|
---|
| 47 | if (!IsHandleCreated)
|
---|
| 48 | return;
|
---|
[3250] | 49 | IAsyncResult result = BeginInvoke(method, args);
|
---|
| 50 | result.AsyncWaitHandle.WaitOne(1000, false);
|
---|
[3266] | 51 | if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
|
---|
[3250] | 52 | else {
|
---|
| 53 | ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
|
---|
[3266] | 54 | new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
|
---|
[3250] | 55 | null, -1, true);
|
---|
| 56 | }
|
---|
[3227] | 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|