private static object[] GetNewParameters(DataGeneratorWrapper dataWrapper, Delegate function) { ParameterInfo[] paras = function.GetMethodInfo().GetParameters(); object[] parametersArray = new object[paras.Length]; for (int i = 0; i < paras.Length; i++) { ParameterInfo para = paras[i]; if (para.ParameterType == typeof(int)) { parametersArray[i] = (dataWrapper.GetIntWrapper()); } else if (para.ParameterType == typeof(double)) { parametersArray[i] = (dataWrapper.GetDoubleWrapper()); } else if (para.ParameterType == typeof(List <double>)) { Random rand = new Random(); parametersArray[i] = (dataWrapper.GetListWrapper(rand.Next(5, 100))); } } return(parametersArray); }
private static void ParallelProcess(FunctionsGeneratorWrapper functionWrapper, DataGeneratorWrapper dataWrapper) { var list = dataWrapper.GetListWrapper(20); Parallel.ForEach <double>(list, num => { Console.WriteLine($"the process for number {num} starts :"); var method = functionWrapper.GetOneDouble(); var res = method.Method.Invoke(method.Target, new object[] { num }); Console.WriteLine($"original number is {num}, parallel result is {res}"); Console.WriteLine($"the end, number {num}"); }); }
static void Main(string[] args) { Assembly dataGeneratorAssembly = Assembly.LoadFile(@"C:\Users\xin.he\source\repos\FunctionsGenerator\Output\DataGenerator.dll"); Type dataGeneratorType = dataGeneratorAssembly.GetType("DataGenerator.DataGenerator"); Assembly functionGeneratorAssembly = Assembly.LoadFile(@"C:\Users\xin.he\source\repos\FunctionsGenerator\Output\FunctionsGenerator.dll"); Type functionGeneratorType = functionGeneratorAssembly.GetType("FunctionsGenerator.FunctionsGenerator"); FunctionsGeneratorWrapper functionWrapper = new FunctionsGeneratorWrapper(functionGeneratorType); DataGeneratorWrapper dataWrapper = new DataGeneratorWrapper(dataGeneratorType); //Console.WriteLine("DataGeneratorWrapper"); //Console.WriteLine("GetIntWrapper"); //for (int i = 0; i < 100; i++) //{ // int intVal = dataWrapper.GetIntWrapper(); // Console.WriteLine(intVal); //} //Console.WriteLine("GetDoubleWrapper"); //for (int i = 0; i < 100; i++) //{ // double val = dataWrapper.GetDoubleWrapper(); // Console.WriteLine(val); //} //Console.WriteLine("GetPrivateDoubleWrapper"); //for (int i = 0; i < 100; i++) //{ // double val = dataWrapper.GetPrivateDoubleWrapper(); // Console.WriteLine(val); //} //Console.WriteLine("GetStringWrapper"); //for (int i = 0; i < 100; i++) //{ // string val = dataWrapper.GetStringWrapper(); // Console.WriteLine(val); //} //Console.WriteLine("GetListWrapper"); //var list = dataWrapper.GetListWrapper(10); //foreach (double d in list) //{ // Console.WriteLine(d); //} //for (int i = 0; i < 100; i++) //{ // Console.WriteLine("Do calculate :" +i); // DoCalculate(functionWrapper, dataWrapper); //} //functionWrapper.GetOneArgument(); //Thread thread = new Thread(() => ParallelProcess(functionWrapper, dataWrapper)); //Thread t2 = new Thread(() => Console.WriteLine("starts starts starts")); //thread.Start(); //t2.Start(); //thread.Join(); //Console.WriteLine("djisdhufi"); //t2.Join(); //Console.WriteLine("oiuiezo"); //ParallelProcess(functionWrapper, dataWrapper); //ThreadPoolProcess(functionWrapper, dataWrapper); //TaskProcess(functionWrapper, dataWrapper); //TaskAwaitAsyncProcessAsync(functionWrapper, dataWrapper); //Thread.Sleep(1000); ListClass listClass = new ListClass(dataWrapper.GetListWrapper(20), functionWrapper.GetDoubleList()); //listClass.MultiThreadList(); listClass.MutexProcess(); //ManualResetEventProcess(functionWrapper, dataWrapper); }