0

my first function fill a listbox with a string from a textbox, the second upload a file with ftp protocol. The two functions are called when i press the key Return and it works fine...but listbox is filled only when the second function has uploaded the file...ideas for first fill the listbox?? thanks

  private void invia(object sender, KeyEventArgs e) {
        if (Alias != "Error:")
        {
            if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
            {
                Scrivi();
                up();
            }
        }

Simple Solution: cl4ptr4p suggest me to make a refresh,

private void invia(object sender, KeyEventArgs e) {
        if (Alias != "Error:")
        {
            if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
            {
                Scrivi();
                listBox1.Update();
                textBox1.Update();
                up();
            }
        }

However a better solution is a BackgroundWorker

Aminesrine
  • 2,082
  • 6
  • 35
  • 64
  • 1
    Chances are, the box is being filled first, it's just not updating till the upload is done. – PiousVenom May 13 '13 at 18:44
  • Smells like [parallel event handling](http://stackoverflow.com/questions/10415801/how-to-parallelize-event-handler-execution-in-c-sharp) is wanted – Austin Salonen May 13 '13 at 18:45
  • What version of .Net are you using? If it's .Net 4.5, I suggest using [await/async](http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx). If it's earlier than 4.5, I suggest using [BackgroundWorker()](http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx) to do the work in the background. – Matthew Watson May 13 '13 at 18:50
  • thanks CL4PTR4P adding a stupid line its works fine :) – Antonio Piergiacomo May 13 '13 at 18:52

0 Answers0