0

I have a method and something weird is happening

  public void UpdateProgressBar(double newValue)
  {                       
        // Make sure we don't go over the maximum value for the progress bar
        if (newValue > _maxValueProgressBar)
            newValue = _maxValueProgressBar;

        // Make sure we don't go under the minimum value for the progress bar
        if (newValue < _minValueProgressBar)
            newValue = _minValueProgressBar;

         if (!NSThread.Current.IsMainThread)
             {
             using (var pool = new NSAutoreleasePool())
             pool.BeginInvokeOnMainThread(delegate
                {
                    JobProgressBar.DoubleValue = newValue;
                });
             }
           else               
               // jobProgressBar.DoubleValue = newValue;
        // InvokeOnMainThread (() => JobProgressBar.DoubleValue=newValue);
  }

as you can see this method must be called from the Mainthread, but when i comment either of the 2 methods bellow the else, my app crash. i will appreciated any help

4

1 回答 1

0

我通常只使用 InvokeOnMainThread,没有理由使用 NSAutoReleasePool。你试过下面的代码吗?

public void UpdateProgressBar(double newValue)
{                       
    // Make sure we don't go over the maximum value for the progress bar
    if (newValue > _maxValueProgressBar)
        newValue = _maxValueProgressBar;

    // Make sure we don't go under the minimum value for the progress bar
    if (newValue < _minValueProgressBar)
        newValue = _minValueProgressBar;

    InvokeOnMainThread (() => JobProgressBar.DoubleValue=newValue);
}
于 2014-05-06T23:53:22.997 回答