小编Adm*_*tor的帖子

c# - 等待2个线程中的1个完成

我的代码中有一个位置,我需要等待在传感器上识别任一个手指,或者用户按下一个键以中止此操作并返回主菜单.
我尝试使用条件变量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)

c# multithreading mutex deadlock fingerprint

3
推荐指数
1
解决办法
99
查看次数

标签 统计

c# ×1

deadlock ×1

fingerprint ×1

multithreading ×1

mutex ×1