검색 및 검색을 시도했지만 어쩌면 잘못된 것을 검색하고 있습니다.C#로드 어셈블리 및 실시간 업데이트 양식
나는 동적으로로드 할 DLL을 추가 할 수있는 일종의 controlpanel을 만들고 있습니다. DLL을로드하는 데 문제가 없으며 실행에 문제가 없습니다. 현재이 작업을 수행하기 위해 "Activator.CreateInstance"를 사용하고 있습니다.
이 방법은 내가 원하는 것을 정확하게하고 있습니다.
1 :
는하지만 ... 나는 몇 가지로 도움이 필요 나는 DLL을 실행 해요 때, 폼 나는 스레드에서 실행하고있어, 비록 동결을 - 어떻게 나는 이것을 피한다?
2 : DLL의 현재 상태를 읽을 수 있어야합니다. DLL 파일은 수퍼 클래스로 만들어져 있으므로 "CurrentStatus"속성을 읽을 수 있습니다. 실행중인 파일의 상태를 읽을 수 있습니까? 프로그램이 DLL을 끝내기를 기다리고있어 멈추는 것처럼 보입니다.
여러분 중 일부는 저를 도울 수 있기를 바랍니다. 사전 :)에서
감사
편집 : 심지어 실제를하지만,
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, curJob.Scheduler_JobAssemblyName + ".dll");
Assembly assembly = Assembly.LoadFile(path);
GenericSchedulerJob o = (GenericSchedulerJob)Activator.CreateInstance(Type.GetType(curJob.Scheduler_JobAssemblyName + "." + curJob.Scheduler_JobAssemblyName + ", " + curJob.Scheduler_JobAssemblyName, true));
Thread thread = new Thread(() => ExecuteDLL(ref o, "RunJob", row));
thread.Start();
while (!o.JobFinished)
{
// Do something (update status, etc.)
}
private string ExecuteDLL(ref GenericSchedulerJob job, string methodName, DataGridViewRow row)
{
string returnVal;
if (job != null)
{
// Get method
MethodInfo mi = job.GetType().GetMethod(methodName); // Get method info
if (mi != null)
{
// Let's start ...
returnVal = (string)mi.Invoke(job, null); // Execute method with parameters
// job is the SuperClass, where I can read the status from
}
else
{
returnVal = "Method <" + methodName + "> not found in class."; // Error ..
}
}
else
{
returnVal = "Class not found in external plugin."; // Error ..
}
return "";
}
죄송합니다, 내 크리스탈 볼이 수리를 위해, 당신은 것입니다 – nvoigt
완료, 첫 번째 코드는 timer_tick에 있습니다. 특정 간격으로 실행되는 스케줄러이므로 – Oxholm