public TimetableCheckRunner(IPluginInterface pluginInterface) { var checks = pluginInterface.GetRegistered <ITimetableCheck>(); pluginInterface.FileStateChanged += (s, e) => { if (pluginInterface.Timetable == null) { return; } var clone = pluginInterface.Timetable.Clone(); if (lastTask != null && cancelTokenSource != null && !lastTask.IsCompleted && !cancelTokenSource.IsCancellationRequested) { cancelTokenSource.Cancel(); } cancelTokenSource = new CancellationTokenSource(); lastTask = new Task(tk => { var token = (CancellationToken)tk; var list = new List <string>(); foreach (var check in checks) { token.ThrowIfCancellationRequested(); list.AddRange(check.Check(clone)); } token.ThrowIfCancellationRequested(); Application.Instance.Invoke(() => { lock (uiLock) { if (list.Any() && form == null) { GetForm().Show(); } if (gridView != null && gridView.Visible) { gridView.DataStore = list.ToArray(); } } }); }, cancelTokenSource.Token, cancelTokenSource.Token); lastTask.Start(); }; pluginInterface.AppClosing += (s, e) => form?.Close(); }
private void FDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int id; string sId; switch (FModalitatFormulari) { case ModalitatFormulari.Mostra: if (FClasseFitxa == null) { return; } foreach (DataGridViewCell oneCell in FDataGridView.SelectedCells) { if (oneCell.Selected) { sId = (FDataSet.Tables[FTaula].Rows[oneCell.RowIndex])[0].ToString(); id = Int32.Parse(sId); // Usem Reflection (https://msdn.microsoft.com/en-us/library/mt656691.aspx) // Jeff Richter shows that calling a method by reflection is about 1000 times slower than calling it normally. // http://stackoverflow.com/questions/25458/how-costly-is-net-reflection MethodInfo info = FClasseFitxa.GetMethod( "Mostra", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); object value = info.Invoke(null, new object[] { FConnexio, id }); } } break; case ModalitatFormulari.Busca: foreach (DataGridViewCell oneCell in FDataGridView.SelectedCells) { if (oneCell.Selected) { sId = (FDataSet.Tables[FTaula].Rows[oneCell.RowIndex])[0].ToString(); id = Int32.Parse(sId); ValorRetorn = sId; } } FForm.Close(); break; } }
void btnClose_Click(object sender, EventArgs e) { FForm.Close(); }