I am calling a C++ function from C# using p/invoke, this function has an infinite loop (capturing frames to a file) which should be broken when an event is happened in C#.
How can I break that loop (which terminates that function)?
I tried to run this function in a thread in C#, and abort that thread when termination is needed. But the abort function didn't work.
Thread thread = new Thread(myMethod);
thread.Start();
// to terminate the function
thread.Abort(); //didn't respond
Probably the safest way is to do two things:
StopRecording
that sets a global variable inside your native codeStopRecording
has been called (and if so, break out of the loop)This lets it terminate naturally without requiring any heavy-handed terminations.