Bonjour,
Dans un service windows, je dois exécuter des transactions ftp dans plusieurs threads.
On m'a conseillé de faire un System.Threading.Timer pour exécuter l'appel de façon cyclique.
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 public class ThreadManager : IDisposable { internal List<CustomersCluster> AllCustomers { get; private set; } private List<Thread> _threads; public ThreadManager(List<CustomersCluster> allCustomers) { AllCustomers = allCustomers; } public void GenerateThreads() { if (AllCustomers != null) { _threads = new List<Thread>(); foreach (CustomersCluster cluster in AllCustomers) { FileMovingManager fmm = new FileMovingManager(cluster); Thread thread = new Thread(new ThreadStart(fmm.Start)); thread.Start(); } } } public void Dispose() { if (_threads != null) foreach (Thread t in _threads) t.Abort(); AllCustomers = null; _threads = null; } }
Mais ça ne marche pas Execute n'est jamais appelée... :arf: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 public class FileMovingManager { private CustomersCluster _customers; private List<MailSender> _mails; public static string MailSendFrom { get; set; } public static string SmtpServer { get; set; } private Timer _timer; public FileMovingManager(CustomersCluster customers) { _customers = customers; _autoEvent = new AutoResetEvent(false); } public void Start() { TimerCallback loopProcess = new TimerCallback(this.Execute); _timer = new Timer(loopProcess, null, _customers.Interval, _customers.Interval); //this.Execute(new Object()); } public void Stop() { _timer.Dispose(); } private void Execute(object o) { [...]
un coup de main ?
merci d'avance