Hello. I use the AForge framework to capture images from the camera. Capture occurs during the execution of an event. But by the time the AcceptTcpClientAsync method is executed, the video variable (bitmap picture) is still null. How to make the event run before the AcceptTcpClientAsync method? Next, the bitmap variable is needed in the CodingImages method.
private void Form1_Load(object sender, EventArgs e) { StartCapture(); Form1 async = new Form1(51510); async.Start(); Console.ReadLine(); } public void StartCapture() { VidoeCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); FinalVideo = new VideoCaptureDevice(VidoeCaptureDevices[0].MonikerString); FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[2]; FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); FinalVideo.Start(); Thread.Sleep(2000); } void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) { video = (Bitmap)eventArgs.Frame.Clone(); } public async void Start() { //Thread.Sleep(10000); IPAddress ipAddre = IPAddress.Loopback; TcpListener listener = new TcpListener(ipAddre, _listeningPort); listener.Start(); LogMessage("Server is running"); LogMessage("Listening on port " + _listeningPort); while (true) { //CaptureImageFromCamera captureFromCamera = new CaptureImageFromCamera(); //Bitmap image = captureFromCamera.StartCapture(); CodingImage img = new CodingImage(); buffer = img.CodingImages(video); count = buffer.Length; lenght = buffer.Length.ToString(); LogMessage("Waiting for connections..."); try { var tcpClient = await listener.AcceptTcpClientAsync(); HandleConnectionAsync(tcpClient); } catch (Exception exp) { LogMessage(exp.ToString()); } i++; } }