C# two functions called on one keyevent, ok but the first wait for the second to finish

127 Views Asked by At

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

0

There are 0 best solutions below