private async void TimerViewerCount_Tick(object sender, EventArgs e) { await Task.Delay(200); try { await Task.Run(() => { if (!string.IsNullOrEmpty(textBoxVideoId.Text)) { var result = _youtubeApi.GetCurrentStreamViewCount(textBoxVideoId.Text); using (var db = new DbEntities(Helper.EntityConnectionString)) { var item = new liveBroadcastsViewCount { Date = DateTime.Now, Count = (long)result, VideoId = textBoxVideoId.Text }; db.liveBroadcastsViewCount.Add(item); db.SaveChanges(); } } }); } catch (Exception ex) { ShowErrorOnPanel = ex.Message + ex.InnerException?.Message; } }