CROSSTHREADING - APPEL D'UNE MÉTHODE VIA UN DÉLÉGUÉ SYNCHRONE

Xya Messages postés 103 Date d'inscription lundi 8 juillet 2002 Statut Membre Dernière intervention 24 novembre 2005 - 24 nov. 2005 à 17:28
Ziad270 Messages postés 5 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 17 août 2006 - 17 août 2006 à 07:14
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/34658-crossthreading-appel-d-une-methode-via-un-delegue-synchrone

Ziad270 Messages postés 5 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 17 août 2006
17 août 2006 à 07:14
Merci Beaucoup !!
Xya Messages postés 103 Date d'inscription lundi 8 juillet 2002 Statut Membre Dernière intervention 24 novembre 2005
24 nov. 2005 à 17:28
Ou plus simple, comme on a un timer:

using System.Timers;

Timer timerIcon = new Timer();

public Form1()
{
...
//indique que tous les événements du timer (qui s'exécutent sur un autre thread)
//seront déclenchés à travers Control.Invoke/BeginInvoke
timerIcon.SynchronizingObject = this;
timerIcon.Interval = 1000.0;
timerIcon.Elapsed += new ElapsedEventHandler( t_Tick );
}

private void ThreadMethod()
{
timerIcon.Start();
}
Rejoignez-nous