Hi
Can you tell me what the difference is between these methods of attaching an event handler?
//Method 1
this.button4.Click += new RoutedEventHandler(button4_Click);
//Method 2
this.button4.Click += button4_Click;
...
void button4_Click(object sender, RoutedEventArgs e) { }
...
Today we faced a quite simple problem that were made even simpler by the dear predicates. We had a kind of event log and wanted to filter it client side (Windows Forms) using a list of criterias. We began by implementing to filter by a number of categories.
private List<Events> FilterEventsByCategory(List<Events> events,
...
I was registering to an event in my class, and as per usual I was lazy and just use the autocomplete feature built into Visual Studio 2008 Pro which auto creates the delegate creation and it's associated method.
public abstract class FooBase
{
protected event EventHandler<MyValueChangedArgs> MyValueChanged;
protected FooBase()
...
I am curious why C# allows me to ignore delegate parameters in some cases but not others.
For instance this is permitted:
Action<int> action = delegate { Console.WriteLine("delegate"); };
but this is not:
Action<int> action = () => Console.WriteLine("lambda");
Is there a way to initialize a delegate and ignore the parameters using...
i have a long running function¹:
public string FindPasswordFromHash(String hash)
{
...
}
which is called like:
private void Button1_Click(object sender, EventArgs e)
{
PasswordTextBox.Text = FindPasswordFromHash(HashTextBox.Text);
}
Now i want to convert it into the asynchronous BeginInvoke/EndInvoke delegate pattern:
priv...
My TextBox won't update! I am using it as a Log to update what other things are doing...
Form 1 code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Collections.Specialized;
using System.Tex...
Hey there,
Does anyone know the best way to check to see if an optional protocol method has been implemented.
I tried this:
if ([self.delegate respondsToSelector:@selector(optionalProtocolMethod:)] )
where delegate is:
id<MyProtocol> delegate;
However - I get an error saying that the function respondsToSelector is not found in th...
I just posted a question about how to get a delegate to update a textbox on another form. Just when I thought I had the answer using Invoke...this happens. Here is my code:
Main Form Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Syst...
I need to bind a method into a function-callback, except this snippet is not legal as discussed in demote-boostfunction-to-a-plain-function-pointer.
What's the simplest way to get this behavior?
struct C {
void m(int x) {
(void) x;
_asm int 3;
}};
typedef void (*cb_t)(int);
int main() {
C c;
boost::function<void (int x...
public delegate T GetObject<T>(SqlDataReader reader);
public delegate KeyValuePair<TKey, TValue> GetObject<TKey, TValue>(SqlDataReader reader);
Is it possible for removing that 2nd line (the two lines are on consecutive lines) to ever make any difference at all, superficial or not?
...
I've been looking at strategy pattern implementation examples and it seems to me like they are very similar to c# delegates. The only difference I see is that strategy pattern implementations don't need to explicitly declare a delegate.
But other than that, they both seem to point to functions that need a specific signature and they ca...
I need to be able to trigger a event whenever an object is added to a Queue<Delegate>.
I created a new class that extends Queue:
public delegate void ChangedEventHandler(object sender, EventArgs e);
public class QueueWithChange<Delegate> : Queue<Delegate>
{
public event ChangedEventHandler Changed;
protected virtual void OnC...
I've read conflicting opinions as to whether every BeginInvoke() has to be matched by an EndInvoke(). Are there any leaks or other problems associated with NOT calling EndInvoke()?
...
Following on from my BeginInvoke()/EndInvoke() question, are there major differences in performance/anything else between Delegate.BeginInvoke() and using QueueUserWorkItem() to invoke a delegate asynchronously?
...
My question is simple: how bad is the following snippet of code? How would you do it?
CancelEventHandler _windowClosing;
private CancelEventHandler WindowClosing
{
set
{
clearEventHandlerList();
this.Closing += value;
_windowClosing = value;
/*
* if calling the method with null parameters,
* it will set ...
I've migrated a .Net legacy .Net project from .Net 1.1 to .Net 3.5 and when I try and run it I'm getting the following error:
Cross-thread operation not valid:
Control 'grpLogin' accessed from a
thread other than the thread it was
created on.
When the a thread (Which I assume is not the UI thread) changes the enabled property...
I am testing a function pointer called ErrorLoggingMethod in a C# DLL to prevent exceptions due to a null value, as below, but it seems that at runtime, the function is actually being executed when I really mean to test its delegate for null. I am inadvertently getting a null exception as a result--just what I am trying to avoid! My or...
I think I'm missing something simple, but I can't figure out exactly what it is.
I'm trying to set up an App with a UITabViewController, and one of the Tabs will have a UITableView and UISearchBar (but no Navigation Controller). I set up the UITabViewController with all the tabs in interface builder, and the views are in their own xib ...
Take the below code:
private void anEvent(object sender, EventArgs e) {
//some code
}
What is the difference between the following ?
[object].[event] += anEvent;
//and
[object].[event] += new EventHandler(anEvent);
[UPDATE]
Apparently, there is no difference between the two...the former is just syntactic sugar of the latte...
In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate?
Example
inputString and result are both declared outside the delegate.
blackList.ForEach(new Action<string>(
delegate(string item)
{
if(inputString.Contains(item)==true)
{
result = true;
...