设置System.Console.WindowHeight会在Mono下抛出System.NotSupportedException

时间:2012-09-20 20:52:14

标签: exception mono console c#-3.0 window

我得到一个Unhandled Exception: System.NotSupportedException: Operation is not supported.使用Ubuntu 11.10在Mono下引发异常。

阅读该属性有效docs可能表明该方法不会造成问题。

关于如何最好地处理或解决这种情况的任何想法?

我的当前解决方案相当尴尬,并没有解决通过System.Console-API设置窗口大小的问题:

        const int defaultConsoleWindowWidth = 80;
        const int defaultConsoleWindowHeight = 25;


        if (pid != PlatformID.Unix && pid != (PlatformID)128) {
            System.Console.WindowHeight = lastConsoleWindowHeight;
            System.Console.WindowWidth = defaultConsoleWindowWidth;
        }else{
            //assume *NIX system
            try {
                var p = new Process();
                p.StartInfo = new ProcessStartInfo(@"stty cols " + defaultConsoleWindowWidth + " rows " + lastConsoleWindowHeight, "-n")
                {
                    UseShellExecute = false
                };

                p.Start();
                p.WaitForExit();
            }
            catch (Exception e) { /*...*/}


        }

我的单声道版

lo@lo-VirtualBox:~/Desktop$ mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS:           __thread
SIGSEGV:       altstack
Notifications: epoll
Architecture:  x86
Disabled:      none
Misc:          softdebug 
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

1 个答案:

答案 0 :(得分:5)

来自master branch on mono on Github Console.cs

[MonoLimitation ("Only works on windows")]
public static int WindowHeight {
    get { return ConsoleDriver.WindowHeight; }
        set { ConsoleDriver.WindowHeight = value; }
}

注意MonoLimitation属性