Hi all
I m new in programming i have epiphan frame grabber which is connected to my other computer to grab screen output i have downloaded SDK from epiphan in which there are few sample codes I have modified VC# code (initial code grab only one picture/screenshot but i have put the method in infinite loop to give it motion) problem is that when i call function(that grab frame) in infinite loop my application hangs and doesnt give any response. I created new thread and put that function in it now it works correctly but when when i comment following lines.
private void GrabFrame()
{
if (OpenGrabber()) {
VideoMode vm = _grabber.DetectVideoMode();
if (vm != null) {
if (vm.IsValid()) {
Frame frame = _grabber.GrabFrame();
if (frame != null) {
//trigger=_grabber.SetMaxFps(1000.0);
// _grabber.Start();
Bitmap bitmap = frame.GetBitmap();
if (bitmap != null) {
//TextOutputAdd("Frame captured (" + vm + ")");
//"Frame captured (" + vm + ")"
// TextOutput.Text = "Frame captured (" + vm + ")" + "\r\n" + TextOutput.Text;
PictureBox.Image = bitmap;
} else {
// TextOutputAdd("Capture format error");");//(display message in text box)
//SetGrabber(null);
}
//TextOutputAdd("Capture failed");");//(display message in text box)
//TextOutputAdd("No signal detected");");//(display message in text box)
//TextOutputAdd("Failed to detect video mode");//(display message in text box)
// SetGrabber(null);
But when I uncomment following lines following error appears
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'TextOutput' accessed from a thread other than the thread it was created on.
Code for button that run thread
private void th_instance() {
for (; ; )
{ GrabFrame();
}}
private void CaptureFrame_Click(object sender, EventArgs e)
//=====================================================
th1 = new Thread(new ThreadStart(th_instance));
th1.Start();
sample source code is attached
i will highly appreciate if somebody could guide me to solve issue and provide me best solution
regards
Attachment: v2u_csharp.rar