tags:

views:

217

answers:

2

I have put some Console.WriteLine calls in to test, but they aren't appearing in the output box?

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("some tetttttttttt23423423423423423ttttttttttttttttttttttt");
            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("some tettttttttttttttttttttttttttttttttt");
        Console.WriteLine(mainForm.myDeliveries.Count);
        foreach (Delivery d in mainForm.myDeliveries)
        {
            lstDeliveryDetails.Items.Add(d.DeliveryName);

        }
    }

Can anyone help??

+4  A: 

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).

Zach Johnson
Like this?System.Diagnostics.Debug.WriteLine("some tetttttttttt23423423423423423ttttttttttttttttttttttt");
Luke
@Luke yes like that
msarchet
@Luke - yes, but you can `Import System.Diagnostics` to make it much simpler. And I prefer using the `Trace` class for this.
Joel Coehoorn
+6  A: 

If you intend to use this output in production, then use the Trace class members. This makes the code portable, you can wire up different types of listeners and output to the console window, debug window, log file, or whatever else you like.

If this is just some temporary debugging code that you're using to verify that certain code is being executed or has the correct values, then use the Debug class as Zach suggests.

If you absolutely must use the console, then you can attach a console in the program's Main method.

Aaronaught