eventargs

Correct usage of generics in event declaration

你离开我真会死。 提交于 2021-01-28 06:41:42
问题 I have a data object which I pass around : public class TimedResult<T> { public ResultRequest Request { get; set; } public T Data { get; set; } public TimeSpan TimeTaken { get; set; } } In my Manager class I have some work done which raises an event : public void Execute(ResultRequest request) { var result = new TimedResult<DataTable>(); // fill data object here OnResult(result); } I have made the OnResult method generic : protected virtual void OnResult<T>(TimedResult<T> result) { if (Result

how to access Custom EventArgs class in Button click event?

冷暖自知 提交于 2020-01-30 08:41:08
问题 As a follow up to: access values within custom eventargs class How do I access public variables within custom Eventargs class, using button click or any other method? Example Custom Event Args class: public class TraderEventArgs: EventArgs { private int _shares; private string _symbol; public TraderEventArgs(int shs, string sym) { this._shares = shs; this._symbol = sym; } public decimal Price { get {return _prices;} } public int Shares { get { return _shares; } } } Code behind button_click

EventArgs.Empty clarification?

蹲街弑〆低调 提交于 2020-01-02 09:32:07
问题 I have a method protected void Item_Click(object sender, EventArgs e) { } I wanted that other code to call this method. ( didn't really need the sender nor e ) something like : Item_Click(null, null) But then I remembered I can use EventArgs.Empty instead. Mouse hovering over it shows : Wait...What ? EventArgs.Empty represents an event ? it is not. it should represent empty argument not an event. just like string.empty represent empty string . Am I missing something here? 回答1: It's just poor

EventArgs.Empty clarification?

旧街凉风 提交于 2020-01-02 09:29:13
问题 I have a method protected void Item_Click(object sender, EventArgs e) { } I wanted that other code to call this method. ( didn't really need the sender nor e ) something like : Item_Click(null, null) But then I remembered I can use EventArgs.Empty instead. Mouse hovering over it shows : Wait...What ? EventArgs.Empty represents an event ? it is not. it should represent empty argument not an event. just like string.empty represent empty string . Am I missing something here? 回答1: It's just poor

How do I make an eventhandler run asynchronously?

落花浮王杯 提交于 2019-12-28 04:50:31
问题 I am writing a Visual C# program that executes a continuous loop of operations on a secondary thread. Occasionally when that thread finishes a task I want it to trigger an eventhandler. My program does that but the when the event handler is triggered, the secondary thread waits until the event handler is finished before continuing the thread. How do I make it continue? Here is the way I currently have it structured... class TestClass { private Thread SecondaryThread; public event EventHandler

Pass object in click/tapped event handler in Xamarin Forms

强颜欢笑 提交于 2019-12-22 04:18:16
问题 Here is my job class: public class Job { public string Id{ get; set;} public string Name{ get; set;} } And here is my ListView: public class JobListePage:ContentPage { // Members private ListView lstView; // Constructor public JobListePage () { // Set members lstView = new ListView (); // Create job objects Job[] jobs = {new Job(){Id="1", Name="Benny"}, new Job(){Id="2", Name="Lukas"}}; // Fill listview with job objects lstView.ItemsSource = jobs; // HOW CAN I PASS THE TAPPED OBJECT HERE???

Why use EventArgs.Empty instead of null?

点点圈 提交于 2019-12-18 10:58:08
问题 I recall reading, on multiple occasions and in multiple locations, that when firing the typical event: protected virtual OnSomethingHappened() { this.SomethingHappened(this, EventArgs.Empty); } e should be EventArgs.Empty if there are no interesting event args, not null. I've followed the guidance in my code, but I realized that I'm not clear on why that's the preferred technique. Why does the stated contract prefer EventArgs.Empty over null? 回答1: I believe the reasoning behind the NOT NULL

Why to not use a custom class instead of inheriting the EventArgs class

旧城冷巷雨未停 提交于 2019-12-17 19:37:22
问题 I'm wondering why should I use a class that inherits from the EventArgs class instead of using a custom class that will do the same job for me when passing event data? 回答1: You don't have to inherit from EventArgs , but it allows people using your classes to use and handle generic *Handler(object sender, EventArgs e) declarations. If you don't inherit from EventArgs , then they have to use explicitly typed *Handler(object sender, YairsFakeEventArgs e) The same goes for just using custom

Does .NET have a built-in EventArgs<T>?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 07:25:48
问题 I am getting ready to create a generic EventArgs class for event args that carry a single argument: public class EventArg<T> : EventArgs { // Property variable private readonly T p_EventData; // Constructor public EventArg(T data) { p_EventData = data; } // Property for EventArgs argument public T Data { get { return p_EventData; } } } Before I do that, does C# have the same feature built in to the language? I seem to recall coming across something like that when C# 2.0 came out, but now I

C# NumericUpDown.OnValueChanged, how it was changed?

天涯浪子 提交于 2019-12-14 03:58:47
问题 I would like to ask how to make custom EventArgs for existing event handler. Lets say, that I have NumericUpDown numericUpDown control and I want handler for its OnValueChanged event. Double clicking to ValueChanged in visual studio makes snippet like this private void numericUpDown_ValueChanged(object sender, EventArgs e) { } However, I'd like to know how it was changed (like +5, -4.7), but plain EventArgs does not have this information. Maybe Decimal change = Value - Decimal.Parse(Text)