private void CallBackEvent(int winNum, BloombergTicker data, string text, Image image, string errorMessage) { if (_blpGetDataCallback != null) { ALLQProgressArgs arg = new ALLQProgressArgs(); arg.Windownum = winNum; arg.ISIN = data.ISIN; arg.Text = text; arg.Image = image; if (!string.IsNullOrEmpty(errorMessage)) { arg.IsError = true; arg.ErrorMessage = errorMessage; } _blpGetDataCallback.Report(arg); } }
// 解析畫面 private async Task GetScreenDataAsync(int winNum, BloombergTicker processTicker) { string clipboardText = null; Image clipboardImage = null; Stopwatch timerRetryCopyWaitTime = new Stopwatch(); try { ClipboardHelper.Clear(); // input copy function base.CopyScreen(winNum); await SleepAsync(300); timerRetryCopyWaitTime.Restart(); DateTime timeOutDate = DateTime.Now.Add(TimeSpan.FromSeconds(20)); bool success = false; while (!success && (DateTime.Now < timeOutDate)) { clipboardText = ClipboardHelper.GetText(); if (string.IsNullOrEmpty(clipboardText) || clipboardText.Length < 100) { clipboardText = null; } else { clipboardImage = ClipboardHelper.GetImage(); } if (clipboardText != null && clipboardImage != null) { success = true; } else { // wait 100 Milliseconds if (DateTime.Now < timeOutDate.AddMilliseconds(100)) { await SleepAsync(100); } // resend copy function after 2 seconds if (timerRetryCopyWaitTime.Elapsed.TotalMilliseconds > 2000) { ClipboardHelper.Clear(); base.CopyScreen(winNum); await SleepAsync(2000); timerRetryCopyWaitTime.Restart(); } } } // Callback if (success) { CallBackEvent(winNum, processTicker, clipboardText, clipboardImage, ""); } else { CallBackEvent(winNum, processTicker, clipboardText, clipboardImage, "Timeout!"); } } catch (Exception ex) { CallBackEvent(winNum, processTicker, clipboardText, clipboardImage, ex.Message); throw; } }