public void RunEvents() { while (true) { SomeEvent.Invoke(); } }
public void DoSomething() { if (SomeEvent != null) { SomeEvent.Invoke(); } }
private void LecturerSearch(string lecturerInitials, int experience, string phone) { IEnumerable <Subject> request = subjects.Select(x => x); if (lecturerInitials != "") { request = request.Where(item => item.Lecturer.Initials.Contains(lecturerInitials)); SomeEvent.Invoke("Поиск по инициалам преподавателя", request.ToList()); } if (experience > 0) { request = request.Where(item => item.Lecturer.Experience == experience); SomeEvent.Invoke("Поиск по опыту работы", request.ToList()); } if (phone != "( ) - -") { request = request.Where(item => item.Lecturer.Phone.Contains(phone)); SomeEvent.Invoke("Поиск по номеру телефона", request.ToList()); } this.subjects = request.ToList(); ShowSubjectCollection(request); ShowLecturersFromCollection(request); }
protected void OnFoo(EventArgs e) { SomeEvent?.Invoke(this, e); SomeEvent?.Invoke(null, e); // Noncompliant {{Make the sender on this event invocation not null.}} // ^^^^^^^^^^^^^^^^ SomeEvent?.Invoke(this, null); // Noncompliant {{Use 'EventArgs.Empty' instead of null as the event args of this event invocation.}} SomeEvent?.Invoke(null, null); // Noncompliant // Noncompliant@-1 SomeEvent(null, e); // Noncompliant {{Make the sender on this event invocation not null.}} // ^^^^^^^^^^^^^^^^^^ SomeEvent.Invoke(this, e); SomeStaticEvent?.Invoke(null, e); SomeStaticEvent?.Invoke(this, e); // Noncompliant {{Make the sender on this static event invocation null.}} SomeStaticEvent?.Invoke(null, null); // Noncompliant {{Use 'EventArgs.Empty' instead of null as the event args of this event invocation.}} SomeStaticEvent?.Invoke(this, null); // Noncompliant // Noncompliant@-1 SomeStaticEvent(this, e); // Noncompliant {{Make the sender on this static event invocation null.}} SomeEvent?.Invoke(default(object), e); // Compliant - we don't handle default(T) SomeEvent?.Invoke(this, default(EventArgs)); // Compliant - we don't handle default(T) }
private void eventRaiser() { foreach (var item in _queue.GetConsumingEnumerable()) { SomeEvent?.Invoke(item); } Console.WriteLine("Exiting from eventRaiser()"); }
public void RaiseEventOnOtherThread() { Task.Run(async() => { await Task.Delay(TimeSpan.FromSeconds(2)); SomeEvent?.Invoke(); }); }
public bool RaiseEvent(double amount) { if (SomeEvent != null) { SomeEvent.Invoke(amount); return(true); } return(false); }
public EventStarterTwo() { timer = new Timer((delegate(object state) { if (SomeEvent != null) { SomeEvent.Invoke(this, EventArgs.Empty); } }), null, 10 * 1000, 1000 * 10); }
public static void InvokeSomeEvent() { // Make sure event is only invoked if someone is listening if (SomeEvent == null) { return; } SomeEvent.Invoke(); }
private void LecturerRegex_button_Click(object sender, EventArgs e) { Regex regex = new Regex(@"^\w[Пан]"); var request = subjects.Where(item => regex.IsMatch(item.Lecturer.Initials)); SomeEvent.Invoke("Поиск по регулярному выражению 1", request.ToList()); ShowSubjectCollection(request); ShowLecturersFromCollection(request); }
private void LecturerRegex2_button_Click(object sender, EventArgs e) { Regex regex = new Regex(@"\(\d{2}\)\s\d+[5]-\d{2}-\d{2}"); var request = subjects.Where(item => regex.IsMatch(item.Lecturer.Phone)); SomeEvent.Invoke("Поиск по регулярному выражению 2", request.ToList()); ShowSubjectCollection(request); ShowLecturersFromCollection(request); }
private void run() { queue = new ActionBlock <SomeEventArgs>(item => SomeEvent?.Invoke(item)); // Subscribe to my own event (this just for demonstration purposes!) this.SomeEvent += Program_SomeEvent; // Raise 1000 events. for (int i = 0; i < 1000; ++i) { OnSomeEvent(i); } // Signal that the queue is not going to get any new items. queue.Complete(); // Wait a couple of seconds. Thread.Sleep(2000); Console.WriteLine("Done."); }
private void run() { queue = new ActionBlock <SomeEventArgs>(item => SomeEvent?.Invoke(item)); // Subscribe to my own event (this just for demonstration purposes!) this.SomeEvent += Program_SomeEvent; // Raise 100 events. for (int i = 0; i < 100; ++i) { OnSomeEvent(i); Console.WriteLine("Raised event " + i); } Console.WriteLine("Signalling that queue is complete."); queue.Complete(); Console.WriteLine("Waiting for queue to be processed."); queue.Completion.Wait(); Console.WriteLine("Done."); }
internal Task Run(CancellationToken cancellationToken) { Console.WriteLine($"AsyncEvents.Run #1, Thread = {Thread.CurrentThread.ManagedThreadId}"); return(Task.Run(async() => { while (!cancellationToken.IsCancellationRequested) { try { Console.WriteLine(); Console.WriteLine($"AsyncEvents.Run #2, Thread = {Thread.CurrentThread.ManagedThreadId}"); await Task.Delay(2000, cancellationToken); Console.WriteLine($"AsyncEvents.Run #3, Thread = {Thread.CurrentThread.ManagedThreadId}"); await OutOfProcessCall(cancellationToken); Console.WriteLine($"AsyncEvents.Run #4, Thread = {Thread.CurrentThread.ManagedThreadId}"); SomeEvent?.Invoke(this, new EventArgs()); } catch (OperationCanceledException operationCanceledException) { Console.WriteLine($"===> AsyncEvents.Run.OperationCanceledException, Thread = {Thread.CurrentThread.ManagedThreadId}"); if (operationCanceledException.CancellationToken.Equals(cancellationToken)) { Console.WriteLine($"===> AsyncEvents.Run.OperationCanceledException, Rethrowing, Thread = {Thread.CurrentThread.ManagedThreadId}"); throw; } else { Console.WriteLine($"===> AsyncEvents.Run.OperationCanceledException, Logging/Retrying, Thread = {Thread.CurrentThread.ManagedThreadId}"); } } catch (AggregateException aggregateException) { Console.WriteLine($"===> AsyncEvents.Run.AggregateException, Thread = {Thread.CurrentThread.ManagedThreadId}"); aggregateException.Handle((e) => e is OperationCanceledException); throw; } } }, cancellationToken)); }
private void SaveToXML_button_Click(object sender, EventArgs e) { XmlSerializer xml = new XmlSerializer(typeof(List <Subject>)); try { using (StreamWriter sw = new StreamWriter("SortByResult.xml", false)) { xml.Serialize(sw, this.subjects); } MessageBox.Show("Serialization is done. File saved.", "Success"); } catch (Exception exc) { MessageBox.Show(exc.Message); } SomeEvent.Invoke("Отсортированный список сохранён в XML документ", this.subjects); }
private void SaveToXML_button_Click(object sender, EventArgs e) { XmlSerializer xml = new XmlSerializer(typeof(List <Subject>)); try { using (StreamWriter sw = new StreamWriter("SearchResult.xml", false)) { xml.Serialize(sw, this.subjects); } MessageBox.Show("Serialization is done. File saved.", "Success"); } catch (Exception exc) { MessageBox.Show(exc.Message); } SomeEvent.Invoke("Сформированная коллекция сериализована и записана в XML файл", this.subjects); }
private void SortByNumberOfLectures(List <Subject> subjects) { IEnumerable <Subject> request = subjects.Select(x => x); if (SortLecturesByIncreasing_radioButton.Checked == true) { request = request.OrderBy(item => (int)item.NumberOfLectures); SomeEvent.Invoke("Отсортирован список по количеству лекций, по возрастанию", request.ToList()); } else { request = request.OrderByDescending(item => (int)item.NumberOfLectures); SomeEvent.Invoke("Отсортирован список по количеству лекций, по убыванию", request.ToList()); } this.subjects = request.ToList(); ShowSubjectCollection(request); ShowLecturersFromCollection(request); }
private void button1_Click(object sender, EventArgs e) { Counter++; counterLabel.Text = Counter.ToString(); _counter++; if (_counter >= 3) { if (SomeEvent != null) { SomeEvent.Invoke(sender, new EventArgs()); } if (CounterEvent != null) { CounterEvent.Invoke(sender, ); } _counter = 0; } }
private void YearSemesterSearch(int year, int semester) { IEnumerable <Subject> request = subjects.Select(x => x); if (year > 0) { request = request.Where(item => item.Year == year); SomeEvent.Invoke("Поиск по курсу", request.ToList()); } if (semester > 0) { request = request.Where(item => item.Semester == semester); SomeEvent.Invoke("Поиск по семетру", request.ToList()); } this.subjects = request.ToList(); ShowSubjectCollection(subjects); ShowLecturersFromCollection(subjects); }
private void SortByControlForm(List <Subject> subjects) { IEnumerable <Subject> request = subjects.Select(x => x); // TODO: проверить, почему сортировка enum работает некорректно, даже при переводе в int if (SortLecturesByIncreasing_radioButton.Checked == true) { request = request.OrderBy(item => (int)item.Control); } else { request = request.OrderByDescending(item => (int)item.Control); } this.subjects = request.ToList(); SomeEvent.Invoke("Отсортирован список по типу контроля", this.subjects); ShowSubjectCollection(request); ShowLecturersFromCollection(request); }
public void OnSomeEvent() { //if (SomeEvent != null) // SomeEvent(); SomeEvent?.Invoke(); // лучше так }
public async Task RaiseSomeEvent() { await SomeEvent?.Invoke(); }
public void CallSomeEvent() { SomeEvent?.Invoke(); }
public void OnSomeEvent() { SomeEvent?.Invoke(); }
protected virtual void OnSomeEvent() { SomeEvent?.Invoke(this, EventArgs.Empty); }
protected virtual void OnSomeEvent(string obj) { SomeEvent?.Invoke("Это из эвента" + obj); }
public void RaiseEvent() { SomeEvent?.Invoke(this, EventArgs.Empty); }
private class SomeNestedType { } // Nested class private void Raise() { SomeEvent?.Invoke(this, EventArgs.Empty); }
protected virtual void OnSomeEvent(CustomEventArgs e) { SomeEvent?.Invoke(this, e); }
public event EventHandler SomeEvent; // Instance event private void TriggeEvent() { SomeEvent?.Invoke(this, EventArgs.Empty); }