개요 :어떻게 매개 변수로 콜백을받는 DLL 메서드를 동적으로 호출합니까?
는 동적으로 .dll을로드하고 자신의 메소드를 호출하는 응용 프로그램을 writting하고있다.
dllName = (string) e.Argument;
// Assembling Complete path for the .dll file
completePath = Path.Combine(ConfigurationManager.AppSettings["DllsFolder"], dllName);
Assembly assembler = Assembly.LoadFrom (completePath);
// Creating Instance of Crawler Object (Dynamically)
dllWithoutExtension = Path.GetFileNameWithoutExtension (dllName);
Type crawlerType = assembler.GetType (dllWithoutExtension + ".Crawler");
object crawlerObj = assembler.CreateInstance (crawlerType.FullName);
// Fetching reference to the methods that must be invoked
MethodInfo crawlMethod = crawlerType.GetMethod ("StartCrawling");
MethodInfo setCallbackMethod = crawlerType.GetMethod ("SetCallback");
: 배경에, 내가 "거기"무슨 일이 일어나고 있는지에 대한 UI를 통지 코드의
조각을 콜백을했습니다 O를 .dll을 이후
은/중공업을하고있다 여태까지는 그런대로 잘됐다. 문제는 내가이 있지만, 작동하지 않는이 코드는 작동public void Notify (string courseName, int subjects, int semesters)
{
string course = courseName;
int a = subjects;
int b = semesters;
}
이
Crawler crawler = new Crawler();
crawler.SetCallback (Notify);
crawler.StartCrawling();
을 (콜백 선언이 작동하면 바로 테스트 할)은 "콜백"메소드를 선언에도 그래도, 그
setCallbackMethod.Invoke(crawlerObj, new object[] { Notify }); // this method fails, bc its a callback parameter
crawlMethod.Invoke(crawlerObj, new object[] {true} ); // This method works, bc its a bool parameter
,하지만 당신은 단지 객체를 전달할 수 있습니다 . 그 이유는 부울을 통과시키는 이유입니다. 이 메서드를 대리자로 사용하고 싶습니까? –
매개 변수로 콜백 메서드를받는 dll에서 메서드를 호출 (호출)하려고합니다. 이것은 기본적으로 내가하려는 일이며, 내가 할 수있는 방법이 있습니까? 방법이없는 경우 전체 앱 아키텍처를 검토해야 할 수도 있습니다. –
첫 번째'crawlMethod.Invoke (...);가'setCallbackMethod.Invoke (...);'가 아니어야합니까? –