런타임에 어셈블리를로드하고 Reflections (MethodInfo.Invoke)를 사용하여 메서드를 호출합니다.비동기 런타임 메서드 호출
이제 이러한 호출을 비동기 적으로 만들고 싶습니다. 그래서 Delegate.BeginInvoke()를 사용하려고합니다. 하지만 런타임에 함수 이름을 제공하여 대리인 인스턴스를 만드는 방법을 모르겠습니다. (모든 예제에서는 컴파일 타임에 인스턴스가 delegate 된 인스턴스 타겟을가집니다.) 호출 할 메소드가 포함 된 MethodInfo 객체가 있습니다. 이것을 할 수있는 방법이 있습니까?
public void Invocation(Object[] inputObjs)
{
public delegate string DelegateMethodInfo(int num);
Assembly assm = Assembly.Load(assemblyName);
Type type = assm.GetType(className);
Type[] ctorParams = new Type[0];
Object[] objs = new Object[0];
ConstructorInfo ctorInf = type.GetConstructor(ctorParams);
Object classObj = ctorInf.Invoke(objs);
MethodInfo methodInf = type.GetMethod(methodName);
// Need asynchronous invocation.
//Object retObj = methodInf.Invoke(classObj, inputObjs);
DelegateMethodInfo del = new DelegateMethodInfo(???); // How to instantiate the delegate???
del.BeginInvoke((int)inputObjs[0], null, null);
}
그것이 정확겠습니까 사용할 수 있습니까? 어쨌든 나에게 더 나은 접근법처럼 보입니다. –
그건 꽤 합리적인 설명, 예. –