开发者

wpf console application not returning to prompt

I've got a wpf "console" application with the following application class:

public partial class App : Application
{
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bo开发者_运维技巧ol AttachConsole(uint dwProcessId);

    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool FreeConsole();

    const uint ATTACH_PARENT_PROCESS = 0x0ffffffff;

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        AttachConsole(ATTACH_PARENT_PROCESS);

        Console.WriteLine("test1");

        FreeConsole();

        System.Environment.Exit(0);
    }
}

When i start it from the console the text "test1" appears but then the console cursor just blinks and the prompt does not appear until I hit Enter. I did remove the StartupURI statement. How to force the application to behave like a console app and return to prompt after the execution? (Windows 7 32 bit).


Instead of setting it as a Windows Application output, use a Console Application output type. The only drawback is that the console will stay open while the windows application is running. I suppose since you can get the processId of the console, you might be able to kill it after launch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜