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

penderi
  • 8,673
  • 5
  • 45
  • 62
user2984254
  • 109
  • 1
  • 7

1 Answers1

0

I normally just use InvokeOnMainThread, not had a reason to use NSAutoReleasePool. Have you tried the code below?

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);
}
Gareth
  • 1