none
Show wait animation while executing query?? RRS feed

  • Question

  •  

    Does anyone knows how it.

     

    I have this code when i hit the button

     

     

     

    Code Snippet

    Me.PicWait.Visible=True

    Me.Datagrid.Datasource=Executequery(Connection,Command)

    Me.PicWaitVisible=False

     

     

    The idea is to show an animated picture while the query is executing, but when the query starts it halts the events on the from until it's finished, i tried the "Application.Doevents" but didn't work.

     

    Any Advice?

    Thursday, January 24, 2008 5:28 PM

Answers

  • In order to make this work, you will need to use multithreading. I would recommend that you use BackgroundWorker control in your application.

     

    Code Snippet

    backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

     

    private void someButton_Click(object sender, EventArgs e)

    {

    PicWaitVisible.Visible = true;

    backgroundWorker.RunWorkerAsync();

    }

     

    private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

    {

    PicWaitVisible.Visible = false;

    if (!e.Cancelled && e.Error == null)

    {

    Datagrid.DataSource = e.Result;

    }

    else

    {

    //handle error

    }

    }

     

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)

    {

    e.Result = Executequery(Connection,Command);

    }

     

     

     

    Hope that helps.
    Thursday, January 24, 2008 6:34 PM
  • In that case, you can use a different thread to execute the query. You will need to update your windows form by raising an event from your thread and catching it on the form level. Take a look at this example: http://msdn2.microsoft.com/en-us/library/3s8xdz5c(vs.71).aspx.

    Thursday, January 24, 2008 6:54 PM

All replies

  • In order to make this work, you will need to use multithreading. I would recommend that you use BackgroundWorker control in your application.

     

    Code Snippet

    backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

     

    private void someButton_Click(object sender, EventArgs e)

    {

    PicWaitVisible.Visible = true;

    backgroundWorker.RunWorkerAsync();

    }

     

    private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

    {

    PicWaitVisible.Visible = false;

    if (!e.Cancelled && e.Error == null)

    {

    Datagrid.DataSource = e.Result;

    }

    else

    {

    //handle error

    }

    }

     

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)

    {

    e.Result = Executequery(Connection,Command);

    }

     

     

     

    Hope that helps.
    Thursday, January 24, 2008 6:34 PM
  • This is the answer to that problem in VS 2005, but since i'm stuck with VS 2003 and Net Framework 1.1 i'm out of that option, is there any other way to solve this for the Net F 1.1???

    Thursday, January 24, 2008 6:43 PM
  • In that case, you can use a different thread to execute the query. You will need to update your windows form by raising an event from your thread and catching it on the form level. Take a look at this example: http://msdn2.microsoft.com/en-us/library/3s8xdz5c(vs.71).aspx.

    Thursday, January 24, 2008 6:54 PM