Solved

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

Posted on 2014-03-13
2
337 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
Comment Utility
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
Comment Utility
Oh for god sake... that simple..
Thx, it worked
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 23
ConsoleSql 1 12
Convert to Hour/minute textbox and compare 3 35
Different Delete Messages 7 10
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now