我的代码中有一个位置,我需要等待在传感器上识别任一个手指,或者用户按下一个键以中止此操作并返回主菜单.
我尝试使用条件变量Monitor和锁定概念之类的东西但是当我尝试提醒主线程时,没有任何反应.
码:
private static object _syncFinger = new object(); // used for syncing
private static bool AttemptIdentify()
{
// waiting for either the user cancels or a finger is inserted
lock (_syncFinger)
{
Thread tEscape = new Thread(new ThreadStart(HandleIdentifyEscape));
Thread tIdentify = new Thread(new ThreadStart(HandleIdentify));
tEscape.IsBackground = false;
tIdentify.IsBackground = false;
tEscape.Start();
tIdentify.Start();
Monitor.Wait(_syncFinger); // -> Wait part
}
// Checking the change in the locked object
if (_syncFinger is FingerData) // checking for identity found
{ …Run Code Online (Sandbox Code Playgroud)