Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:41:17+00:00 2026-06-05T07:41:17+00:00

I have a c++/cli wrapper class which grabs frames from a camera and sends

  • 0

I have a c++/cli wrapper class which grabs frames from a camera and sends them as events.

A WPF test application Starts the camera, and updates the images.
When I click Stop, it usually ends in a deadlock, on m->streamThread->Join(). I’m suspecting the problem has to do with the frame handling event in the WPF, rather than the wrapper code.

namespace WpfTestApp
{
    public partial class Window1 : Window
    {

    private void OnFrameArrived(object sender, EventArgs e)
    {
        Action a = delegate 
        {
            // this uses Imaging.CreateBitmapSourceFromMemorySection
            // to copy the frame data to the image memory

            m_colorImage.UpdateImage(e.Image);
        };

        Dispatcher.Invoke(a);
    }

    private void startBtn_Click(object sender, RoutedEventArgs e)
    {
        m_camera.FrameArrived += m_frameHandler;
        m_camera.Start();
    }

    private void Stop()
    {
        m_camera.FrameArrived -= m_frameHandler;
        m_camera.Stop();
    }
    }
}

// Camera.h
public ref class Camera
{
public:
    delegate void FrameArrivedHandler(Object^ sender, DGEventArgs^ e);        
    event FrameArrivedHandler^ FrameArrived;

    void Start();
    void Stop();

 private:
    void StreamThreadWorker();
    Thread^ m_streamThread;
    bool m_isStreaming;
 }

 // Camera.cpp
void Camera::Start() 
{
    if (m_isStreaming)
        return;

    m_isStreaming = true;

    m_streamThread = gcnew Thread(gcnew ThreadStart(this, &Camera::StreamThreadWorker));
    m_streamThread->Start();
}

void Camera::Stop()
{
    if (!m_isStreaming)
        return;

    m_isStreaming = false;

    m_streamThread->Join(); // stuck here
}

void Camera::StreamThreadWorker()
{
    EventArgs^ eventArgs = gcnew EventArgs();

    while (m_isStreaming)
    {
        eventArgs->Image = Camera->GetImage();

        FrameArrived(this, eventArgs);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:41:19+00:00Added an answer on June 5, 2026 at 7:41 am

    likely what happens is: you click Stop, this gets handled in the WPF ui dispatcher thread. So the Join call is in the ui dispatcher thread. However this same thread is also responsible for drawing the frames (the invoked call to UpdateImage). As a result, the StreamThreadWorker is waiting on FrameArrived to finish, but that cannot finish because the thread is waiting for Stop to finish. There’s your deadlock.

    So in order to get the StreamThreadWorker to finish, it must not be blocked by Stop. An easy way to achive this is to stop the thread from within another thread:

    void Camera::Stop()
    {
      ...
    
      gcnew Thread( gcnew ThreadStart( this, &Camera::DoStopThread ) )->Start();
    }
    
    void Camera::DoStopThread()
    {
      if( !m_streamThread.Join( 3000 ) )
        HandleThreadDidNotStopInTimeError(); //notify listeners there's a serious problem
      m_streamThread.Abort();
      m_streamThread = null;
      RaiseThreadStoppedEvent(); //notify listeners that the thread stopped
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++/CLI based install application which needs to close another app I've
I have a C++/CLI application which needs to format a partition (single drive letter
I have an application (CLI) which includes the feature of editing account information. It
In some C++/CLI code I have a native class which has a factory method
I have created a C++/CLI mixed DLL which I am using from C# Winforms
I have to use a class/assembly made in C# .NET from native C++ application.
I want to move my C# application from GDI+ to Direct2D (C++/CLI wrapper) for
I have created a C++ CLI wrapper for native C++ code, which in turn
I have a C++/CLI wrapper class to interop between C# and native C++. I'm
I have a C++/CLI wrapper around native .lib and .h files. I use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.