Bonjour,
j'essaye de faire effectuer une tache longue (requetes en bdd) a un background worker, mais mon interface graphique se fige pendant le traitement. j'ai pourtant cru comprendre que c'était l'intéret du backgroundworker: que ca ne fige pas. j'ai également essayé avec un thread, ca marche, mais ca plante au bout de quelques minutes.
auriez vous une idée pour ne plus que ca freeze/plante ?
voici un bout de mon code:
Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
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
39
40
41
42
43
44
45
46 public maClasse() { estActif = true; // Set up the Background Worker Events _backgroundWorker.DoWork += _backgroundWorker_DoWork; _backgroundWorker.RunWorkerCompleted += _backgroundWorker_RunWorkerCompleted; } BackgroundWorker _backgroundWorker = new BackgroundWorker(); void _backgroundWorker_DoWork(object sender, DoWorkEventArgs evt) { while (estActif) { lock (this) { // connection/requete BDD oracle Emettre(this); // emmet un evennement a la vue, afin qu'elle se MAJ } } } // Completed Method void _backgroundWorker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs evt) { if (evt.Cancelled) { MessageBox.Show("Cancelled"); } else if (evt.Error != null) { MessageBox.Show("Exception Thrown"); } else { Activer(); } } public void Activer() { // Run the Background Worker estActif=true; _backgroundWorker.RunWorkerAsync(); } public void Desactiver() // arrete le requetage { estActif = false; }
merci d'avance a vous !
Partager