I'm designing a plugin system for my app.
there is a "Start" button in UI. When user clicks on it, app should call a method in plugin dll asynchronously and change "Start" to "Stop". That method could include almost anything as it is for plugin. When user clicks "Stop", that asynchronous method should be terminated immediately.
I wanted to use Thread.Abort();
but everyone recommends not to use it. If I use CancellationTokenSource, I have to add cancellation handling to all plugins and I prefer not to do this.
I need something like a force shutdown, unplug or destroy (if needed!) for a PC. The only important thing for me is immediate stop. No cleanup or things like this are needed as my app unloads the plugin after using it and plugins have nothing to do with main app codes.
Isn't there anyway to start a method asynchronously and have full control on it? Is it OK to use Thread.Abort();
in this situation (if I guarantee the dll won't catch thread abort exception)?
EDIT: Is there any way to actively monitor cancellation token in plugin dll (class) asynchronously while running method and kill method when requested?
EDIT2: I think it is not a good idea but what about creating a new process and use Process.kill()
?