Пример #1
0
        public async Task <string> LookForMap(CancellationToken cancellationToken)
        {
            try
            {
                OcrAsyncChecker.CheckThread(OcrAsyncChecker.LookForMapAsyncChecker);

                var finder  = new Finder();
                var sb      = new StringBuilder();
                var logUtil = new LogUtil(@".\logLookForMap.txt");
                logUtil.Log("Started");

                int attempts = 0;
                while (!cancellationToken.IsCancellationRequested && IsInitialized)
                {
                    sb.Clear();
                    if (SuspendScanning)
                    {
                        await Task.Delay(1000, cancellationToken).ConfigureAwait(false);

                        continue;
                    }
                    bool fullyTrustable = false;
                    lock (ImageProcessingHelper.GDILock)
                    {
                        var screenPath = finder.CaptureScreen();
                        fullyTrustable = _recognizer.ProcessMap(finder.CaptureMapArea(screenPath), sb);
                    }

                    if (!string.IsNullOrEmpty(sb.ToString()))
                    {
                        if (fullyTrustable)
                        {
                            break;
                        }

                        await Task.Delay(500, cancellationToken).ConfigureAwait(false);

                        var sbConfirm = new StringBuilder();
                        lock (ImageProcessingHelper.GDILock)
                        {
                            var screenPath = finder.CaptureScreen();
                            _recognizer.ProcessMap(finder.CaptureMapArea(screenPath), sbConfirm);
                            if (sbConfirm.ToString() == sb.ToString())
                            {
                                break;
                            }
                        }
                    }

                    attempts++;
                    if (attempts == 5)
                    {
                        return(string.Empty);
                    }

                    await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
                }
                logUtil.Flush();
                return(sb.ToString());
            }
            finally
            {
                OcrAsyncChecker.CleanThread(OcrAsyncChecker.LookForMapAsyncChecker);
            }
        }