Memory 没有足够的存储空间用于“Console.ReadLine”`

Memory 没有足够的存储空间用于“Console.ReadLine”`,memory,service,console,readline,Memory,Service,Console,Readline,我正在使用双服务/控制台模型来测试我的服务。聚光灯下的代码是: static void Main(string[] args) { // Seems important to use the same service instance, regardless of debug or runtime. var service = new HostService(); service.EventLog.EntryWritten += EventLogEntryWritten;

我正在使用双服务/控制台模型来测试我的服务。聚光灯下的代码是:

static void Main(string[] args)
{
    // Seems important to use the same service instance, regardless of debug or runtime.
    var service = new HostService();
    service.EventLog.EntryWritten += EventLogEntryWritten;

    if (Environment.UserInteractive)
    {
        service.OnStart(args);
        Console.WriteLine("Host Service is running. Press any key to terminate.");
        Console.ReadLine();
        service.OnStop();
    }
    else
    {
        var servicesToRun = new ServiceBase[] { service };
        Run(servicesToRun);
    }
}
当我在调试器下运行应用程序时,在
Console.ReadLine()行使用F5
我得到一个
System.IO.IOException
,带有“没有足够的存储空间来处理这个命令”


ReadLine
的唯一用途是等待有人按键结束应用程序,因此我无法想象数据来自何处,需要如此多的存储。

这是一项服务,其输出可能设置为Windows应用程序,将输出更改为Console应用程序,这应该会消失。

我遇到同样的问题,我在“项目属性”下找到了设置,但我正在创建windows应用程序,因此无法更改应用程序类型

这是我使用的代码

Dim t As Task = New Task(AddressOf DownloadPageAsync)
t.Start()
Console.WriteLine("Downloading page...")
Console.ReadLine()
异步子下载页面异步()


结束Sub

非常感谢。我在这些小麻烦上浪费了太多的时间,我不得不花一整晚的时间来处理真正的代码。我希望有一种方法可以分别为调试和发布指定项目输出类型(控制台/窗口)。我尝试将-console参数添加到调试参数中,但得到了相同的结果。
Using client As HttpClient = New HttpClient()
    Using response As HttpResponseMessage = Await client.GetAsync(page)
        Using content As HttpContent = response.Content
            ' Get contents of page as a String.
            Dim result As String = Await content.ReadAsStringAsync()
            ' If data exists, print a substring.
            If result IsNot Nothing And result.Length > 50 Then
                Console.WriteLine(result.Substring(0, 50) + "...")
            End If
        End Using
    End Using
End Using