How to enable conversion of covariant array?

I have a task of stitching an image, which can take a lot of time, so I run it as a separate 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 } 

Should I worry about a warning about sharing the array together below, or am I doing something wrong?

Covariant conversion of an array from string [] to object [] may throw a runtime exception on a write operation

+7
source share
1 answer

Got this - the problem is that you pass string[] , as if it were an array of arguments for the delegate, when you really want it to be the only argument:

 BeginInvoke(new Action<string[]>(StitchTask), new object[] { openFileDialog.FileNames }); 

Everything that gives you a warning warns you of implicitly converting string[] to object[] , which is reasonable because something taking an object[] parameter might try to write:

 array[0] = new object(); 

In this case, this is not a problem ... but the problem associated with trying to map each line to a separate delegation parameter is the problem.

+13
source

All Articles