Home > front end >  System.InvalidCastException: Unable to cast object of type 'SelectedObjectCollection' to t
System.InvalidCastException: Unable to cast object of type 'SelectedObjectCollection' to t

Time:01-17

System.InvalidCastException: Unable to cast object of type 'SelectedObjectCollection' to type ,System.Collections.Generic.lEnumerable'1[System.String]

I need help understanding this runtime error. I am fairly sure that the below is the problem, but have not been able to find a solution that works.

Parallel.ForEach(Of String)(Me.clb1.SelectedItems, Sub(clb1)

Parallel.ForEach(of String)(Me.CheckedListBox1.SelectedItems, Sub(xxx) <-Not sure what goes here.

The error message highlights the entire Sub but the rest was cut and pasted from working code.

CodePudding user response:

I read the instructions of Lambda and found a simpler example. The is dawned on me what I needed to do.

    For cnt = 0 To ListBox1.Items.Count - 1
        MyFiles.Add(ListBox1.Items(cnt))
    Next

    Parallel.ForEach(MyFiles, Sub(F)

Now I need to fix the code to handle the multi-threading code, but that is another question that I am not ready to ask yet. Thanks.

  • Related