FFImageLoading.Drawables.SelfDisposingBitmapDrawable.SetIsDisplayed C# (CSharp) Method

SetIsDisplayed() public method

This should only be called by Views that are actually going to draw the drawable. Increments or decrements the internal displayed reference count. If the internal reference count becomes 0, NoLongerDisplayed will be raised. If the internal reference count becomes 1, Displayed will be raised. This method should be called from the main thread.
public SetIsDisplayed ( bool isDisplayed ) : void
isDisplayed bool If set to true reference count is /// incremented, otherwise it is decremented.
return void
        public virtual void SetIsDisplayed(bool isDisplayed)
        {
            EventHandler handler = null;
            lock (monitor)
            {
                if (isDisplayed && !HasValidBitmap)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot redisplay this drawable, its resources have been disposed.");
                }
                else if (isDisplayed)
                {
                    display_ref_count++;
                    if (display_ref_count == 1)
                    {
                        handler = Displayed;
                    }
                }
                else
                {
                    display_ref_count--;
                }

                if (display_ref_count <= 0)
                {
                    display_ref_count = 0;
                    handler = NoLongerDisplayed;
                }
            }
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
            CheckState();
        }