I have a MyFunction that may take several datatypes, which are all very similar. I just want to pass all these different types of data into MyFunction with multithreading and type cast in MyFunction. Is this something possible? Is using dictionary a good idea? Please advise.
Main(){
Parallel.ForEach(objectType1, MyFunction)
Parallel.ForEach(objectType2, MyFunction)
Parallel.ForEach(objectType3, MyFunction)
}
MyFunction(object arg){
Dictionary<string, object> d = (Dictionary<string, object>) arg;
Type1 t1;
Type2 t2;
Type3 t3;
if (d.Key == "Type1") {
t1 = (Type1) d.Value;
ProcessType1(t1);
}
else if (d.Key == "Type2") {
t2 = (Type2) d.Value;
ProcessType2(t2);
}
else if (d.Key == "Type3") {
t3 = (Type3) d.Value;
ProcessType3(t3);
}
}
You could do: