Rather than using a C# stub that gets written to disk, explore using the full in-memory technique used to execute msf stages.
Superficially, this looks like it will be slightly slower overall than the current approach, due to there simply being more to type, but it could be faster to get the window off screen if that function can be invoked immediately, rather than only when the entire C# stub has been added as a type.
As an additional bonus, this leaves less of a forensic footprint, so generally a win.