Out of memory for Console.ReadLine`.

I am using a dual service / console model to test my service. Spotlight Code:

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 launch the application under the debugger using F5, in the line Console.ReadLine(); I get a System.IO.IOException , with "Not enough memory to process this command."

The only purpose of ReadLine is to wait for someone to press a key to finish the application, so I can’t imagine where the data is coming from, which requires so many storages.

+6
source share
2 answers

This is a service, and its output is most likely installed in a Windows application, change the output to a console application, and this should disappear.

+10
source

I had the same problem, I found the parameter in the project properties, but I am creating a Windows application, so I can not change the type of application.

This is the code I'm using.

 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

+1
source

Source: https://habr.com/ru/post/982595/


All Articles