Interlocked.Increment 无法使用我的 Get 变量名

Interlocked.Increment not working with my Get variable name

我有 WPF 应用程序和我的作品 method 在不同的线程中播放我的文件

这是我的 Global 变量,它更新了我的 UI:

public static int _totalFilesSent;

现在因为我在我的模型中实现 INotifyPropertyChanged 我还有这个:

public static int TotalFilesSent
{
    get { return _totalFilesSent; }
    set
    {
        _totalFilesSent = value;
        OnStaticlPropertyChanged("TotalFilesSent");
    }
}

(我没有添加事件函数,因为这与这里无关)。

所以每次我这样更新我的 Global variable 时:

Interlocked.Increment(ref _totalFilesSent );

现在因为我需要用我的 INotifyPropertyChanged 事件更新我的 UI 我需要使用 TotalFilesSent 而不是 _totalFilesSent 但是这样我得到了这个编译错误:

A property, indexer or dynamic member access may not be passed as an out or ref parameter.

这是什么意思,我该如何解决?

您可以在调用 Interlocked.Increment:

后轻松引发 StaticPropertyChanged 事件
private static int _totalFilesSent;

public static int TotalFilesSent
{
    get { return _totalFilesSent; }
}

public static void IncrementTotalFilesSent()
{
    Interlocked.Increment(ref _totalFilesSent);
    OnStaticPropertyChanged("TotalFilesSent");
}