Bonjour a tous,
Je suis en train de réaliser une petite application métier comprenant (entre autre un spash screen. J'ai vu pas mal de problème comme le mien, mais je n'arrive pas pour autant a y trouver une solution, c'est pouquoi je vais tenter de vous l'expliquer.
Mon Splash screen est un winform classique, avec une picture et une progressbar, le traitement et les chargements divers se font dans un second thread, une fois ma progressbar arrivée a terme j'utilise une méthode pour ouvrir le formulaire principal de l'appli (dans le thread principal via un beginInvoke et un delegate), puis je tente de faire un this.Close(); pour fermer le slash screen, cependant celui ci ouvre brièvement l'application principal et me fait l'équivalent d'un Application.Exit();
Comment résoudre le problème svp? a noter que je fais le code suivant pour lancer le form principal:
Merci d'avance...
Code : 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace AndroidStudio { public partial class loadForm : Form { private Thread loadingThread; private delegate void updateProgressBar(int level, string description); private delegate void displayMain(); public loadForm() { InitializeComponent(); loadingThread = new Thread(loadIDE); loadingThread.Start(); } private void loadIDE() { while (true) { if (this.progressLoading.Value + 1 >= this.progressLoading.Maximum) { this.BeginInvoke(new displayMain(displayMainIDE)); } else { this.progressLoading.BeginInvoke(new updateProgressBar(setProgress), new object[] { this.progressLoading.Value + 1, "Chargement en cours" }); Thread.Sleep(1000); } } } private void setProgress(int level, string description) { progressLoading.Value = level; lblInfos.Text = description; } private void btnClose_Click(object sender, EventArgs e) { if (loadingThread.IsAlive) { loadingThread.Abort(); } Application.Exit(); } private void displayMainIDE() { defaultForm defaultForm = new defaultForm(); defaultForm.Show(); loadingThread.Abort(); this.Close(); } private void mainPicture_Click(object sender, EventArgs e) { } } }
Partager