En fait, je dois charger des données dans un Listview, et ca peut prendre du temps.
Donc pendant le temps de chargement et d'affichage, j'affiche une form pour faire patienter l'utilsateur...
Voila comment je m'y prend :
try
{
Thread tWait = new Thread(new ThreadStart(PleaseWait));
tWait.IsBackground = true;
tWait.Start();
// Ici : Chargement des données à afficher depuis le fichier
// Ici : Remplissage du listView avec ses données
tWait.Abort();
... // Ici encore deux trois opérations
}
catch
{
// Affiche une messageBox d'erreur
}
// Affichage de la form qui fait patienter
private void PleaseWait()
{
this._frmWait = new frmWaiting(unString);
this._frmWait.ShowDialog();
}
// Voici le code que j'ai dans la form qui fait patienter
public frmWaiting(string s)
{
this.InitializeComponent(); if(s !
null) label.Text s
}
// Dans le load de la form, je mets un timer en marche.
// A chaque ticks, je fais tourner une picture box dans 90°
// Dans la méthode Dispose je fais un timer.Dispose (si jamais...)
private void tmrRotateImage_Tick(object sender, System.EventArgs e)
{
this.pictureBox.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.pictureBox.Refresh();
}
Le problème : Parfois (environ 1 fois 10) j'ai le message d'erreur suivant qui se produit (une exception non gérée blabalba) System.Threading.ThreadAbortException: Thread was being aborted.
Alors si quelqu'un à une idée du problème, c'est volentier que je prends la solution!
Merci.
[Pub]
http://www.csharpfr.com/auteurdetail.aspx?ID=13319 [\Pub]
C# forever