Quantcast
Viewing all articles
Browse latest Browse all 12583

Starting timers from inside a callback function

Hi,

I am working on a small application which grabs bmps from a video source.

I have a function which responds to mouse clicks on a "Grab" button. From this function I can start a timer, and then stop it from the timers event handler function. However I'm unable to start and stop the timer from the callback function obvisouly due to a different context / scope. So I have created another handler function which has the same scope as the timer, from this funtion I'm able to update lables in my form without any problems, but I can't start the timer. Is there any reason why I can't start the timer from my callback handler?

I have posted a block of code below.

Andrew

private void btnGrab_Click(object sender, EventArgs e)
        {
            // If the "Grab" button has been pressed indicate to the preview callback function
            // that the next frame is to be captured 
            m_bCapture = true;
            btnGrab.Enabled = false;           
        }

        public void PreviewCBs(IntPtr lpContext, IntPtr bpData, int nDataSize, int nChannel, int isKeyFrame, int nFrameCnt)
        {
            GrabForm cGrabForm = (GrabForm)GCHandle.FromIntPtr(lpContext).Target;

            cGrabForm.PreviewCB(bpData, nDataSize, nChannel, isKeyFrame, nFrameCnt);

        }

        public void PreviewCB(IntPtr bpData, int nDataSize, int nChannel, int isKeyFrame, int nFrameCnt)
        {
            if (m_bCapture)
            {
                String sFilename;

                PreviewTimer.Start();
                PreviewTimer.Enabled = true;
                                
                btnGrab.Enabled = true;
            }
        }  


Viewing all articles
Browse latest Browse all 12583

Trending Articles