cs0123 - 'ProgressChanged' 没有重载匹配 .net 核心中的委托 'EventHandler'<int>

cs0123 - no overload for 'ProgressChanged' matches delegate 'EventHandler'<int> in .net core

我无法注册进度更改事件。带有问题标题中的上述错误消息。

代码:

public class AudioFileSearcher
{
    public AudioFileSearcher(string searchPath, bool includeSubFolders, Views.SoundListView.SoundList parentView)
    {
        this.progress1 = new Progress<int>();
        progress1.ProgressChanged += backgroundWorker1_ProgressChanged; //<- Error Here!
    }
    // void backgroundWorker1_ProgressChanged(object sender, EventArgs e) // also not working
    void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // Do something
    }
    public async Task FindAudioFiles(IProgress<int> progress)
    {
        foreach (string item in longItemList)
        {
            // do long operation
            if (progress != null)
            progress.Report(0);
        }
    }
}

我检查的每个示例和堆栈溢出问题都表明问题在于

void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)

正确的是

void backgroundWorker1_ProgressChanged(object sender, EventArgs e) // also not working

不幸的是,我检查过的关于 IProgress 的其他问题都有不完整或伪示例,这些示例对我不起作用。

我找到的例子都是错误的。而不是这个:

public class AudioFileSearcher
{
    public AudioFileSearcher(string searchPath, bool includeSubFolders, Views.SoundListView.SoundList parentView)
    {
        this.progress1 = new Progress<int>();
        progress1.ProgressChanged += backgroundWorker1_ProgressChanged; //<- Error Here!
        Task.Run(async () => await FindAudioFiles(progress1));
    }
    void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // Do something
    }
}

试试这个:

public class AudioFileSearcher
{
    public AudioFileSearcher(string searchPath, bool includeSubFolders, Views.SoundListView.SoundList parentView)
    {
        this.progress1 = new Progress<int>(
        {
            backgroundWorker1_ProgressChanged();
        });
        Task.Run(async () => await FindAudioFiles(progress1));
    }
    void backgroundWorker1_ProgressChanged()
    {
        // Do something
    }
}