C# - Thread - Classe Splash Form
Hello,
J'ai crée une classe pour afficher une form pendant les traitements assez longs (formSplash), mais je reçoit l'erreur suivante -->
Code:
Opération inter-threads non valide : le contrôle 'FormSplash' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
.
A mon avis, il faudrait utiliser des "delegate" mais je ne vois pas du tout comment faire ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Test
{
class Splash
{
static Thread thread = null;
static FormSplash formSplash = null;
public static void launch()
{
if (formSplash == null)
{
thread = new Thread(new ThreadStart(showForm));
thread.IsBackground = true;
thread.Start();
}
}
public static void stop()
{
formSplash.Close();
}
private static void showForm()
{
formSplash = new FormSplash();
formSplash.ShowDialog();
}
}
} |
J'appelle depuis mainForm -->
Code:
1 2 3 4
|
Splash.launch();
/* ... */
Splash.stop(); |
Pouvez-vous m'aider svp ?