Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/01/10 15:36:10 (14 years ago)
Author:
mkommend
Message:

updated AsynchronousContentView to work semi-asynchronous (ticket #953)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/AsynchronousContentView.cs

    r3229 r3250  
    2525    /// <param name="method">The delegate to invoke.</param>
    2626    protected new void Invoke(Delegate method) {
    27       IAsyncResult res = base.BeginInvoke(method);
    28       ThreadPool.RegisterWaitForSingleObject(res.AsyncWaitHandle,
    29         new WaitOrTimerCallback((x, b) => { EndInvoke(res); }),
    30         null, -1, true);
     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) EndInvoke(result);
     31      else {
     32        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
     33          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (InvalidOperationException) { } }),
     34          null, -1, true);
     35      }
    3136    }
     37
    3238    /// <summary>
    3339    /// Asynchronous call of GUI updating.
     
    3642    /// <param name="args">The invoke arguments.</param>
    3743    protected new void Invoke(Delegate method, params object[] args) {
    38       IAsyncResult res = base.BeginInvoke(method, args);
    39       ThreadPool.RegisterWaitForSingleObject(res.AsyncWaitHandle,
    40         new WaitOrTimerCallback((x, b) => { EndInvoke(res); }),
    41         null, -1, true);
     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) EndInvoke(result);
     48      else {
     49        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
     50          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (InvalidOperationException) { } }),
     51          null, -1, true);
     52      }
    4253    }
    4354  }
Note: See TracChangeset for help on using the changeset viewer.