When I added the below code to perform async & await,
namespace loadmultipleimages
{
public partial class Form1 : Form
{
VideoCapture capture = new VideoCapture();
delegate void delHugeTask();
public Form1()
{
InitializeComponent();
}
public static /*async*/ Task CopyToAsync( this Stream input, Stream output, CancellationToken cancellationToken = default(CancellationToken))
{
return CopyToAsyncTasks(input, output, cancellationToken).ToTask();
}
private IEnumerable<Task> CopyToAsyncTasks(Stream input, Stream output, CancellationToken cancellationToken)
{
byte[] buffer = new byte[0x1000]; // 4 KiB
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
var bytesReadTask = input.Read(buffer, 0, buffer.Length);
yield return bytesReadTask;
if (bytesReadTask.Result == 0) break;
cancellationToken.ThrowIfCancellationRequested();
yield return output.Write(buffer, 0, bytesReadTask.Result);
}
}
}
}
This error pops up & blue underline under Form 1 at public partial class Form1 : Form
Error 1 Extension method must be defined in a non-generic static class
I know that if you want to use static methods, Class must be defined as static too. But how to work my way around this problem?