How to yield return inside anonymous methods?

后端 未结 7 555
南笙
南笙 2021-01-07 16:43

Basically I have an anonymous method that I use for my BackgroundWorker:

worker.DoWork += ( sender, e ) =>
{
    foreach ( var effect in Glob         


        
7条回答
  •  情书的邮戳
    2021-01-07 17:01

    Ok so I did something like this which does what I wanted (some variables omitted):

    public static void Run ( Action action )
    {
        worker.DoWork += ( sender, e ) =>
        {
            foreach ( var effect in GlobalGraph.Effects )
            {
                var result = image.Apply (effect);
    
                action (100 * ( index / count ), result );
            }
        }
    };
    

    and then in the call site:

    GlobalGraph.Run ( ( p, r ) =>
        {
            this.Progress = p;
            this.EffectResults.Add ( r );
        } );
    

提交回复
热议问题