Hello,
For long processing ...
In order for your helper form to continue running the Gif during processing it will be necessary to start it on a Thread other than the Thread where the processing will be done.
Here is the example of the helper form where your Gif image will be displayed:
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace Connessioni.Elos.DB.Remote.Controls
{
/// <summary>
/// Form padrão para ser exibido quando um processamento longo é iniciado
/// </summary>
public partial class FrWorking : Form
{
/// <summary>
/// Se o form foi iniciado
/// </summary>
public bool Started;
/// <summary>
/// Contrutor
/// </summary>
public FrWorking()
{
InitializeComponent();
}
/// <summary>
/// Exibe o form como dialog
/// </summary>
public void ShowDiag()
{
try
{
Application.DoEvents();
ShowDialog();
}
catch (Exception)
{
//
}
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Form.Shown"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.EventArgs"/> that contains the event data. </param>
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Application.DoEvents();
BringToFront();
Started = true;
}
}
}
Now follow the example of how to use this form:
/// <summary>
/// Carrega a.....
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btLoad_MouseUp(object sender, MouseEventArgs e)
{
//Form a ser exibido durante o processamento
var w = new FrWorking();
//Executando o form auxiliar em uma nova System.Threading.Thread
var t = new Thread(w.ShowDiag);
//Iniciando a Thread
t.Start();
//Aguardando até q a Thread seja iniciada
while (!w.Started) { }
//:) Execute seu processamento aqui, e seja feliz....
try
{
//Fechando form auxiliar
t.Abort();
}
catch (Exception)
{
//
}
}