코드에 액세스 할 수있는 C# DLL을 사용하려고하지만 실제로 코드를 변경하고 사용자 지정 버전을 빌드 할 수 없습니다. 호출 코드는 C# WinForms 프로젝트이고 C# DLL은 WinForms를 사용하여 Windows 시스템 이벤트를 처리합니다. 문제는 DLL이 백그라운드 스레드를 사용하여 DLL 내부에서 Application.Run()을 사용하고 스레드를 중지하거나 중지하는 기본 제공 방법이 있다는 것입니다. 여기에 코드 중 일부이다C# 종료 Application.Run()을 사용하는 스레드
public class DllClass
{
private Thread uithread = null;
private bool uithreadstarted = false;
public DllClass()
{
uithread = new Thread(new ThreadStart(RunDll));
uithread.IsBackground = true;
uithread.SetApartmentState(ApartmentState.STA);
uithread.Start();
do
{
Thread.Sleep(100);
} while (uithreadstarted == false);
}
private void RunDll()
{
//other init stuff here
uithreadstarted = true;
Application.Run();
}
}
분명히 나는 그것이 Application.Exit()를 사용하는 것입니다, 그러나 그것은 또한 내가 원하는 것이 아니다 내 자신의 윈폼 프로젝트를 종료 죽이는 것으로 예상하고있어 방법 우연히 있다. Application.Exit()을 호출하지 않고 응용 프로그램을 닫으면 DLL은 백그라운드에서 계속 실행됩니다. 완료 될 때 DllClass 객체를 인스턴스화하고 사용하고 종료 할 수 있기를 원합니다. 나는 실행중인 스레드의 Thread 객체를 얻는 방법을 생각해 냈지만 Thread.Abort()를 호출하면 실제로 스레드를 죽이지는 않습니다. 강제로 DLL 외부에서 Application.Run() 호출을 중단 할 수있는 방법이 있습니까?