Is it at all possible to run apps that use winforms in Windows docker containers? All of our software heavily relies on winforms, however it is possible to run all of these tools without interacting with the GUI. I attempted to debug the launcher from inside the container and I noticed the application stopped at the Run
function for the WindowsFormsApplicationBase
base class.
using Microsoft.VisualBasic.ApplicationServices;
namespace Program
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyApp myApp = new MyApp();
myApp.Run(args);
}
}
class MyApp : WindowsFormsApplicationBase
}
Call Stack
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine) Unknown
MyApp.exe!MyApp.Program.Main(string[] args) Line 49 C#
CodePudding user response:
Winforms do work in the dotnet/framework/sdk
image. This was tested by creating a simple winforms app that created an empty text file on form showing and form closing since Windows Applications can't use Console.WriteLine()
.
namespace TestGUI_DockerApp
{
public partial class Form1 : Form
{
private int i = 0;
private void ExitTimerTick(object sender, EventArgs e)
{
i ;
if (i > 4)
{
Close();
}
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
DateTime dateTime = DateTime.Now;
string filename = $".\\{dateTime:yyyy_MM_dd_HH_mm_ss_fff}.txt";
File.Create($".\\{filename}");
base.OnFormClosed(e);
}
private void Form1_Shown(object sender, EventArgs e)
{
exitTimer.Enabled = true;
DateTime dateTime = DateTime.Now;
string filename = $".\\{dateTime:yyyy_MM_dd_HH_mm_ss_fff}.txt";
File.Create($".\\{filename}");
}
}
}
I saw two different text files being created and the process closed shortly after that.
The error I was seeing in my original post was due to an unhandled exception being thrown somewhere else in the code. Since it was unhadled, the program was waiting for me to acknowledge it before closing. Since I couldn't acknowledge it, it appeared to be hanging.