Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/AsynchronousContentView.cs @ 3580

Last change on this file since 3580 was 3566, checked in by mkommend, 15 years ago

removed ctors with contents in all views (ticket #972)

File size: 1.9 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    /// <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}
Note: See TracBrowser for help on using the repository browser.