Opened 3 months ago

Last modified 3 months ago

#3069 new defect

Race condition in AsynchronousContentView leads to exception and HL crash — at Initial Version

Reported by: gkronber Owned by:
Priority: medium Milestone:
Component: MainForm.WindowsForms Version:
Keywords: Cc:

Description

There is a race condition whereby in the AsynchronousContentView in the following code 'result' is null, or already disposed within the WaitOrTimerCallback when it is called. This leads to a KeyNotFoundExceptionException in the callback and consequently a crash of HL. The error is hard to reproduce but usually occurs when algorithms are running and working with the Hive Job Manager (which often locks views and shows progress bars).

    /// Asynchronous call of GUI updating.
    /// </summary>
    /// <param name="method">The delegate to invoke.</param>
    /// <param name="args">The invoke arguments.</param>
    protected new void Invoke(Delegate method, params object[] args) {
      // prevents blocking of worker thread in Invoke, if the control is disposed
      IAsyncResult result = BeginInvoke(method, args);
      result.AsyncWaitHandle.WaitOne(1000, false);
      if (result.IsCompleted) try { EndInvoke(result); }
        catch (ObjectDisposedException) { } else {
        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
          null, -1, true);
      }
    }

Change History (0)

Note: See TracTickets for help on using tickets.