I have an image stitching task that could take a lot of time so I run it as a seperate task like this
var result = openFileDialog.ShowDialog();
BeginInvoke(new Action<string[]>(StitchTask), openFileDialog.FileNames);
private void StitchTask(string[] fileNames)
{
// this task could take a lot of time
}
Do I need to worry about the co-variant array conversion warning below or am I doing something wrong?
Co-variant array conversion from string[] to object[] can cause run-time exception on write operation
Got it - the problem is that you're passing a string[]
as if it were an array of arguments for the delegate, when you actually want it as a single argument:
BeginInvoke(new Action<string[]>(StitchTask),
new object[] { openFileDialog.FileNames });
Whatever's giving you the warning is warning you about the implicit conversion of string[]
to object[]
, which is reasonable because something taking an object[]
parameter might try to write:
array[0] = new object();
In this case that isn't the problem... but the fact that it would try to map each string to a separate delegate parameter is a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With