code

Console.WriteLine이 출력 창에 표시되지 않습니다.

codestyles 2020. 10. 14. 07:51
반응형

Console.WriteLine이 출력 창에 표시되지 않습니다.


Console.WriteLine테스트를 위해 몇 가지 호출을 입력 했지만 출력 상자에 나타나지 않습니까?

public static ArrayList myDeliveries = new ArrayList();

public mainForm(){
    InitializeComponent();
}

private void mainForm_Load(object sender, EventArgs e){

    if (!File.Exists("../../MealDeliveries.txt")){
        MessageBox.Show("File not found!");
        return;
    }

    using (StreamReader sr = new StreamReader("../../MealDeliveries.txt")){
        //first line is delivery name 
        string strDeliveryName = sr.ReadLine();
        Console.WriteLine("Test content");

        while (strDeliveryName != null){

            //other lines 
            Delivery d = new Delivery(
                strDeliveryName, 
                sr.ReadLine(),
                sr.ReadLine(), 
                sr.ReadLine(),
                sr.ReadLine(), 
                sr.ReadLine(),
                sr.ReadLine()
            );

            mainForm.myDeliveries.Add(d);

            //check for further values
            strDeliveryName = sr.ReadLine();
        }
    }

    displayDeliveries();


}


private void displayDeliveries(){

    lstDeliveryDetails.Items.Clear();
    Console.WriteLine("Test content");
    Console.WriteLine(mainForm.myDeliveries.Count);
    foreach (Delivery d in mainForm.myDeliveries){
        lstDeliveryDetails.Items.Add(d.DeliveryName);

    }
}

누구든지 도울 수 있습니까 ??


프로덕션에서이 출력을 사용하려면 Trace 클래스 멤버 를 사용하십시오 . 이렇게하면 코드를 이식 할 수 있으며 다양한 유형의 리스너를 연결하고 콘솔 창, 디버그 창, 로그 파일 또는 원하는 다른 항목에 출력 할 수 있습니다.

특정 코드가 실행되고 있는지 또는 올바른 값이 있는지 확인하는 데 사용하는 임시 디버깅 코드 인 경우 Zach가 제안하는 대로 Debug 클래스 를 사용합니다 .

반드시 콘솔을 사용해야하는 경우 프로그램의 메서드에 콘솔연결할있습니다Main .


Console outputs to the console window and Winforms applications do not show the console window. You should be able to use System.Diagnostics.Debug.WriteLine to send output to the output window in your IDE.

Edit: In regards to the problem, have you verified your mainForm_Load is actually being called? You could place a breakpoint at the beginning of mainForm_Load to see. If it is not being called, I suspect that mainForm_Load is not hooked up to the Load event.

Also, it is more efficient and generally better to override On{EventName} instead of subscribing to {EventName} from within derived classes (in your case overriding OnLoad instead of Load).


If you want Console.WriteLine("example text") output to show up in the Debug Output window, temporarily change the Output type of your Application from Console Application to Windows Application.

From menus choose Project + Properties, and navigate to Output type: drop down, change to Windows Application then run your application

Of course you should change it back for building a console application intended to run outside of the IDE.

(tested with Visual Studio 2008 and 2010, expect it should work in latter versions too)


If you are developing a command line application, you can also use Console.ReadLine() at the end of your code to wait for the 'Enter' keypress before closing the console window so that you can read your output. However, both the Trace and Debug answers posted above are better options.


Using Console.WriteLine( "Test" ); is able to write log messages to the Output Window (View Menu --> Output) in Visual Studio for a Windows Forms/WPF project.

However, I encountered a case where it was not working and only System.Diagnostics.Debug.WriteLine( "Test" ); was working. I restarted Visual Studio and Console.WriteLine() started working again. Seems to be a Visual Studio bug.


When issue happening on Mac VS 2017 (Which I faced).

  1. Go to Project >> "Your Project name" options.
  2. An option window will pop up
  3. Go to RUN >> Default menu option
  4. Tick the "Run on external console" option TRUE and say OK

Run your application code now.


Old Thread, But in VS 2015 Console.WriteLine does not Write to Output Window If "Enable the Visual Studio Hosting Process" does not Checked or its Disabled in Project Properties -> Debug tab


Try to uncheck the CheckBox “Use Managed Compatibility Mode” in

Tools => Options => Debugging => General

It worked for me.


Select view>>Output to open output window.

In the output window, you can see the result

참고URL : https://stackoverflow.com/questions/2669463/console-writeline-does-not-show-up-in-output-window

반응형