我在Visual Studio 2008中创建了VB.NET Windows窗体应用程序。从命令行运行程序时,没有任何输出(只有下一个提示)。
我究竟做错了什么?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Debug.Write("Foo")
Debug.Flush()
Console.WriteLine("foo")
Console.Beep(800, 100) 'confirm this function is called'
Me.Close()
End Sub
编辑:程序可以有一个窗体和一个控制台吗?
编辑2: Ho的答案有效。但是,输出出现在下一个命令行提示符下。 Winforms应用程序可以告诉命令行等待它完成而不是立即返回吗?
最佳答案
或者,如果您已经拥有WinForms应用程序,则可以使用AttachConsole API将控制台附加到该应用程序。
using System.Runtime.InteropServices;
...
[DllImport("kernel32.dll")] static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
...
AttachConsole(ATTACH_PARENT_PROCESS);
(格式化为代码)
关于vb.net - Console.Write在Win Forms应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638030/