I have an application that calls my DLL using InvokeMember() as follows:
Assembly OCA = Assembly.LoadFrom("./Modules/ProcessFiles.dll"); Type[] types = OCA.GetTypes(); foreach (var type in types) { //MethodInfo[] methods = type.GetMethods(); if (type.Name == "Converter") { var tmpType = type; var obj = Activator.CreateInstance(tmpType); Thread t = new Thread( () => tmpType.InvokeMember("Run", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, null)); t.Start(); break; } }
My DLL creates a new thread and starts processing. In my DLL, I create a new thread as follows:
Thread thread = new Thread( delegate(){ while(true) { GetFilesInFolder(); Thread.Sleep(120000); } }); ne.Start();
The goal is to periodically check the folder. The problem is that when I close the application that calls my DLL, the process does not close. Is there a way to close all threads?
NB: I cannot change the application, I can only change my DLL.
source share