This bug is happens when the plugin is started from TouchPortal with plugin_start_cmd. Not when starting from Visual Studio and connecting to TouchPortal etc.
When a Console application is started by TouchPortal, the Console.ReadLine() does not hold the application.
Therefor this plugin will just skip the ReadLine part, and close the pluigin.
It can be changed to something like:
//Console.ReadLine();
var manualResetEvent = new ManualResetEvent(false);
manualResetEvent.WaitOne();
This will work, but then there is another issue. When TouchPortal closes, the plugin is still running.
Therefor there are two options, either use Environment.Exit(0); in the OnCloseEventHandler.
This is similar to what the Java SDK does:
@Override
public void onDisconnect(Exception exception) {
// Socket connection is lost or plugin has received close message
if (exception != null) {
exception.printStackTrace();
}
System.exit(0);
}
Or, pick in the OnCloseEventHandler and do a manualResetEvent.Set().
Using a TaskCompleationSource or similar instead of a ManualResetEvent should also work.