Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3301 was 3266, checked in by swagner, 14 years ago

Fixed type of caught exceptions in AsynchronousContentView (#953).

File size: 2.0 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      // prevent blocking of worker thread in Invoke, if the control is disposed
28      IAsyncResult result = BeginInvoke(method);
29      result.AsyncWaitHandle.WaitOne(1000, false);
30      if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
31      else {
32        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
33          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
34          null, -1, true);
35      }
36    }
37
38    /// <summary>
39    /// Asynchronous call of GUI updating.
40    /// </summary>
41    /// <param name="method">The delegate to invoke.</param>
42    /// <param name="args">The invoke arguments.</param>
43    protected new void Invoke(Delegate method, params object[] args) {
44      // prevent blocking of worker thread in Invoke, if the control is disposed
45      IAsyncResult result = BeginInvoke(method, args);
46      result.AsyncWaitHandle.WaitOne(1000, false);
47      if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
48      else {
49        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
50          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
51          null, -1, true);
52      }
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.