Solved

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

Posted on 2014-03-13
2
343 Views
Last Modified: 2014-03-13
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
Comment
Question by:justaphase
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39926716
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
 
LVL 1

Author Closing Comment

by:justaphase
ID: 39926772
Oh for god sake... that simple..
Thx, it worked
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question