Bonjour,

Je développe actuellement une application en C# de videosurveillance

Tout fonctionne, sauf de temps en temps j'ai de cmessage d'erreur :

Une exception de première chance de type 'System.AccessViolationException' s'est produite dans System.Drawing.dll

Et dès que j'ai ce message, mon application s'arrête

Pouvez vous m'aider ?

VOici mon code :
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Data;
using System.Text;
using System.Drawing;
using DirectX.Capture;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using VideoSurveillance;
 
namespace VideoSurveillance
{
    public partial class Form1 : Form
    {
        int nombreintru = 0;
        private Filters InputOptions = new Filters();
        private Filter VideoInput = null;
        private Filter AudioInput = null;
        private Capture CaptureInfo = null;
        Color couleur ;
        Color couleur2 ;
        Bitmap bmp ;
        Bitmap bmp2;
 
        public Form1()
        {
            InitializeComponent();
            label1.Visible = false;
        }
 
 
 
        private void ErrorMessage(Exception e)
        {
            MessageBox.Show(e.Message, "VideoSurveillance", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
 
 
 
        private void button1_Click(object sender, EventArgs e)
        {
            this.Configure();
            CaptureInfo.CaptureFrame();
 
 
          //  CaptureInfo.Filename = Application.StartupPath +"/essai.avi";
          // CaptureInfo.Start();
        }
 
 
 
        private void aProposToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            AboutBox1 apropos = new AboutBox1();
            apropos.Show();
 
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
 
 
            pictureEtat = true;
            CaptureInfo.CaptureFrame();
            timerPhoto.Start();
 
 
 
 
        }
 
        private void quitterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
 
        }
 
 
 
        private void timerPhoto_Tick(object sender, EventArgs e)
        {
            while (timerPhoto.Interval <= 300000)
            {
                timerPhoto.Interval += 1;
 
            }
            detection();
            CaptureInfo.CaptureFrame();
            timerPhoto.Interval = 1;
            timerPhoto.Stop();
            timerPhoto.Start();
 
        }
 
 
 
 
        private void detection()
        {
 
            bmp = pictureBox2.Image as Bitmap;
            bmp2 = pictureBox3.Image as Bitmap;
 
            couleur = bmp.GetPixel(0, 0);
            couleur2 = bmp2.GetPixel(0, 0);
 
 
 
 
            if (couleur.Equals(couleur2))
            {
               // MessageBox.Show("C'est pareil");
            }
            else
            {
             //   MessageBox.Show("Intrusion");
                nombreintru++;
                label1.Visible = true;
                label1.Text = ("Nombre d'intrusions :  " + nombreintru);
                //timerPhoto.Start();
            }
 
 
        }
 
 
 
 
 
 
 
    }
}
Merci et bonne journée