设置System.Console.WindowHeight抛出下单的System.NotSuppor

2019-07-31 18:04发布

我得到一个Unhandled Exception: System.NotSupportedException: Operation is not supported. 唯一的例外是使用Ubuntu 11.10单下提出的。

读取属性的作品 。 该文档可能表明,该方法不构成问题。

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

目前的解决方案是相当尴尬,并没有解决设置通过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)

Answer 1:

从上Github上Console.cs单主分支 :

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

注意MonoLimitation属性



文章来源: Setting System.Console.WindowHeight throws an System.NotSupportedException under Mono