I am creating a custom video player in a C# form. At present the player has a initialising and shutdown routines and a thread running in the background reading video frames and displaying them. I am fairly new to C# so I am trying to establish how best to send the start\stop\pause commands from the GUI thread to the video thread. Should I just use a state variable protected with a lock and poll this every time round my video thread; are there
any other recommendations?
Thanks.
A polled state variable would seem the easiest solution providing your video thread loops regularly enough.
You may not even need a lock, making the state variable
volatileshould be sufficient in C# providing only one thread updates it. (volatilein C# has slightly different semantics than C, and should guarantee that the other thread picks up the new value)