6

I am using a dual service/console model to test a service of mine. The code in the spotlight is:

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);
    }
}

When I run the app under the debugger, using F5, on the line Console.ReadLine(); I get a System.IO.IOException, with "Not enough storage is available to process this command."

The only purpose of the ReadLine is to wait until someone presses a key to end the app, so I can't imagine where the data is coming from that needs so much storage.

ProfK
  • 49,207
  • 121
  • 399
  • 775

2 Answers2

10

This is a service, and its output is likely set to Windows Application, change the output to Console Application and this should go away.

krystan honour
  • 6,523
  • 3
  • 36
  • 63
  • Thank you so much. I have wasted so much time on little nuisances like these I have to spend all night getting on with real code. – ProfK Feb 17 '15 at 13:09
  • I wish there was a way to specify project output type (console/windows) for debug and release separately. I tried adding -console parameter to debug parameters but I get the same result. – nurettin Nov 16 '17 at 09:15
1

I having the same problem, I found the setting under project properties but I am creating a windows application so I can not change the application type.

This is the code I use.

Dim t As Task = New Task(AddressOf DownloadPageAsync)
t.Start()
Console.WriteLine("Downloading page...")
Console.ReadLine()

Async Sub DownloadPageAsync()

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

End Sub

Dave Moon
  • 11
  • 3