Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

C# listbox show added items for 5 seconds and leave app

Hello experts,

I have a simple application where i send some data to a webserver by post. And while i do it i'm adding items to a listbox, just to inform the steps that are being done.
And after all finished the form with the listbox should show the information for 5 seconds and exit application.

My problem is, all the steps are working great with no problems, but while the steps are being done and i'm adding items to the listbox, the listbox doesn't show nothing, just blank. And in the end after all steps are done, wait's the 5 seconds with the listbox continuously  blank  and finally closes...

The code is inside the Form.Shown event, something like this:
private void Form1_Shown(object sender, EventArgs e)
{
    try
    {
        string[] lines = System.IO.File.ReadAllLines(@"C:\tmp\printers.txt");

        foreach (string line in lines)
        {
            responsefromserverRACC = "";
            while (responsefromserverRACC == "")
            {
                listBoxReport.Items.Add("Initiating: " + line);
                // code code
                }
            }
        }


        webClient.Dispose();
        webClientRACC.Dispose();

        System.Threading.Thread.Sleep(10000);
        System.Windows.Forms.Application.Exit();
    }
    catch (Exception em)
    {
        Console.WriteLine("error:");
        MessageBox.Show(em.Message);
    }
}

Open in new window


Should i do this different? In another event?
Or i just can't do it? :)

Thx in advanced,
Michael
0
justaphase
Asked:
justaphase
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
The quick solution would be to simply call Refresh() on the listbox after adding each item:
...

listBoxReport.Items.Add("Initiating: " + line);
listBoxReport.Refresh();

...

Open in new window

0
 
justaphaseAuthor Commented:
Oh for god sake... that simple..
Thx, it worked
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now