'aforge camera won't close, error "thread abort is not supported in this platform"
I am totally new to vb.net and I am trying to incorporate my webcam into the application that i am creating. I have successfully made it run until to the point that i want to close the camera and proceed to other tasks but the camera kept running and when i tried to create a variable that will stop the camera like "camera.stop", i received this error (thread abort is not supported in this platform). i am using vb.net 2019 for this
Imports AForge
Imports AForge.Video
Imports AForge.Video.DirectShow
Imports System.IO
Imports System.Data.SqlClient
Public Class CAMERA
Dim camera As VideoCaptureDevice
Dim bmp As Bitmap
Dim cmd As New SqlCommand
Private Sub Captured(sender As Object, eventArgs As NewFrameEventArgs)
bmp = DirectCast(eventArgs.Frame.Clone(), Bitmap)
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap)
End Sub
Private Sub CAMERA_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cameras As VideoCaptureDeviceForm = New VideoCaptureDeviceForm
If cameras.ShowDialog() = Windows.Forms.DialogResult.OK Then
camera = cameras.VideoDevice
AddHandler camera.NewFrame, New NewFrameEventHandler(AddressOf Captured)
camera.Start()
End If
End Sub
Private Sub CAMERA_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
camera.Stop()
End Sub
Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
Me.Close()
End Sub
Private Sub SButton3_Click_1(sender As Object, e As EventArgs) Handles SButton3.Click
PictureBox2.Image = PictureBox1.Image
End Sub
Private Sub SButton1_Click(sender As Object, e As EventArgs) Handles SButton1.Click
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
PictureBox2.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
MessageBox.Show("PROFILE IMAGE UPDATED")
End Sub
End Class
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
