How to use AsParallel conditionally or attach dynamically at runtime
this is a sample join between two datatable by LINQ
var JoinResult = (from p in dt.AsEnumerable()
join t in dtTax.AsEnumerable()
on p.Field<int>("Tax Id") equals t.Field<int>("Tax Id")
select new
{
ProductName = p.Field<string>("Product Name"),
BrandName = p.Field<string>("Brand Name"),
ProductCategory = t.Field<string>("Product Category"),
TaxCharge = t.Field<int>("Charge")
}).ToList();
some time there could be huge amount of data in two datatable and some time two datatable has small amount of data. when data is small amount then AsParallel () not require because i know AsParallel () will slow down when run for small amount of data but when data volume is big then AsParallel () works good & fast.
please tell me how could i use AsParallel () dynamically as a result when data volume will be large and same way AsParallel () will not be applied when data volume will be small.
i found no good solution for my scenario to attach AsParallel () with my linq query dynamically. please share the know to achieve my goal. thanks
EDIT
I am looking for some dynamic behavior. when joining two small resultset and use AsParallel then joining taking long time but when joining two large resultset and use AsParallel then execution getting faster.
Now i am using AsParallel conditionally this way which is not good for me.
if (dt.rows.count <=50000)
{
var JoinResult = (from p in dt.AsEnumerable()
join t in dtTax.AsEnumerable()
on p.Field<int>("Tax Id") equals t.Field<int>("Tax Id")
select new
{
ProductName = p.Field<string>("Product Name"),
BrandName = p.Field<string>("Brand Name"),
ProductCategory = t.Field<string>("Product Category"),
TaxCharge = t.Field<int>("Charge")
}).ToList();
}
else
{
var JoinResult = (from p in dt.AsEnumerable().AsParallel()
join t in dtTax.AsEnumerable().AsParallel()
on p.Field<int>("Tax Id") equals t.Field<int>("Tax Id")
select new
{
ProductName = p.Field<string>("Product Name"),
BrandName = p.Field<string>("Brand Name"),
ProductCategory = t.Field<string>("Product Category"),
TaxCharge = t.Field<int>("Charge")
}).ToList();
}
how could i develop a something which will detect result is large and then use AsParallel else not use AsParallel. can you please give me any direction to attach AsParallel dynamically ?
Thanks