Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-13
2
Medium Priority
?
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 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

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!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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