在DotNet框架容器中运行WinForms应用



是否有可能在Windows docker容器中运行使用winforms的应用程序?我们所有的软件都严重依赖于winforms,但是不与GUI交互也可以运行所有这些工具。我试图从容器内部调试启动器,我注意到应用程序停在WindowsFormsApplicationBase基类的Run函数处。

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
}

调用堆栈

[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#

Winforms在dotnet/framework/sdk图像中工作。这是通过创建一个简单的winforms应用程序来测试的,该应用程序在表单显示和表单关闭时创建了一个空文本文件,因为Windows应用程序不能使用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}");
}
}
}

我看到正在创建两个不同的文本文件,然后这个进程很快就关闭了。

我在原来的帖子中看到的错误是由于代码中其他地方抛出了一个未处理的异常。因为它是未处理的,程序在关闭前等待我确认它。因为我无法确认,所以它看起来像是挂着的。

最新更新