0

I have a window form having one PictureBox. I have added .gif file to it. This form is kind a progress bar so I am opening this in a separate thread then a main thread. Issue I am having is until all the threads are completed gif image is not start animating.

Please suggest. Below is my code:

private bool StartUploading()
{

    objLoadingThread = new Thread(LoadProgressBar);
    objLoadingThread.Start();
    .. 
    ..
    ..
    ..
    StopProgress = true;
}

// Progress bar
private void LoadProgressBar()
{
    objAlertForm = new AlertForm();
    objAlertForm.Show();
    objAlertForm.Refresh();
    while (!StopProgress)
    {
        for (int i = 0; i <= 100; i++)
        {
            objAlertForm.ProgressValue = i;
            if (StopProgress)
            {
                break;
            }
            Thread.Sleep(100);
        }
    }
    objAlertForm.Hide();
    StopProgress = false;
    objLoadingThread.Abort();
}
Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61

1 Answers1

0

Thread.Sleep will make the main thread to sleep and not the objLoadingThread thread.

If at all you need a delay you can look for some loop with large iteration.

Sathish
  • 29
  • 5