private void PollScanProgress() { IntPtr json = hbFunctions.hb_get_state_json(this.Handle); string statusJson = Marshal.PtrToStringAnsi(json); JsonState state = null; if (!string.IsNullOrEmpty(statusJson)) { state = JsonConvert.DeserializeObject <JsonState>(statusJson); } TaskState taskState = state != null?TaskState.FromRepositoryValue(state.State) : null; if (taskState != null && (taskState == TaskState.Scanning || taskState == TaskState.Searching)) { if (this.ScanProgress != null && state.Scanning != null) { this.ScanProgress(this, new ScanProgressEventArgs(state.Scanning.Progress, state.Scanning.Preview, state.Scanning.PreviewCount, state.Scanning.Title, state.Scanning.TitleCount)); } } else if (taskState != null && taskState == TaskState.ScanDone) { this.scanPollTimer.Stop(); var jsonMsg = hbFunctions.hb_get_title_set_json(this.Handle); this.TitlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg); if (!string.IsNullOrEmpty(this.TitlesJson)) { this.Titles = JsonConvert.DeserializeObject <JsonScanObject>(this.TitlesJson); if (this.Titles != null) { this.FeatureTitle = this.Titles.MainFeature; } } if (this.ScanCompleted != null) { this.ScanCompleted(this, new System.EventArgs()); } } }