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 73 74 75 76 77 78 79
| 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 TestThread
{
public partial class GestionReleve : Form
{
private Thread ThreadIHM;
static public bool Etat;
static private Semaphore Sem1;
static IHMReleve MonIHM;
public delegate void ChangeLabel(Int32 i);
public GestionReleve()
{
InitializeComponent();
Etat = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Sem1 = new Semaphore(1, 1);
ThreadIHM = new Thread(new ThreadStart(AffichageIHM));
ThreadIHM.Start() ;
timer1.Interval = 500;
timer1.Start();
}
private void AffichageIHM()
{
MonIHM = new IHMReleve();
MonIHM.ShowDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < 99; i++)
{
progressBar1.Value = i;
Thread.Sleep(10);
}
timer1.Stop();
this.Hide();
this.Visible = false;
DetectExit();
}
private void DetectExit()
{
Int32 i = 0;
bool et = false;
while (!et)
{
MonIHM.Invoke(new ChangeLabel(MonIHM.SetLabel), i);
//MonIHM .SetLabel (i);
et = MonIHM.GetSortie();
Thread.Sleep (50);
i++;
}
Application.Exit();
}
static public void SetEtat(bool et)
{
Sem1.WaitOne();
Etat = et;
Sem1.Release();
}
}
} |
Partager