Question: We moved from gradle 4 to 6 directly. In one of our methods, we create a task and were executing it earlier. 

```
def myCopy(src, dest, rules) {
    //check some biz logic with rules
    Copy cc = task("cc${dest}",type:Copy)
    cc.from src
    cc.into dest
    //this worked in gradle 4. With gradle 6 it throws an error:Could not find method execute() for arguments
    cc.execute()
}

task doCopy {
    doLast {
        myCopy('resources', 'newResources', [])
    }
}

```

With gradle 6, we get this error: > Could not find method execute() for arguments.

We know execute has been removed, so we tried executing it with finalizedBy:

```
task noop {
    doLast {
        println "Noop..."
    }
}

def myCopy(src, dest, rules) {
    //check some biz logic with rules
    Copy cc = task("cc${dest}",type:Copy)
    cc.from src
    cc.into dest
    //this worked in gradle 4. With gradle 6 it throws an error:Could not find method execute() for arguments
    tasks.getByName("noop").finalizedBy "cc${dest}"
}

task doCopy {
    doLast {
        myCopy('resources', 'newResources', [])
    }
}

```

But this doesn't work either. Any pointers will be great. Thank you!

Answer: 
You can try something like this

```
private CancellationTokenSource cancellationToken;

//start
private void button1_Click(object sender, EventArgs e)
{
    cancellationToken= new CancellationTokenSource();
    Read();
}

private async void Read()
{
    Task.Factory.StartNew(() =>
    {
       listBox1.Items.Insert(0, "Read 1");
    }, cancellationToken.Token);
}

//stop
private void button2_Click(object sender, EventArgs e)
{
    if(cancellationToken!= null) 
    cancellationToken.Cancel();
}

```
i think if you want the thread to be stopped in some cases 
you may do these 

```
 private void button1_Click(object sender, EventArgs e)
{
    var tokenSource2 = new CancellationTokenSource();
    CancellationToken ct = tokenSource2.Token;

    Read(ct);
}

private async void Read( CancellationToken cancellationToken)
{
    if (cancellationToken.IsCancellationRequested)
    {
           Thread.Sleep(4000);
    }
}

```