Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
GeneralRe: Where can I find the code for my book? Pin
Luc Pattyn6-Mar-16 12:49
sitebuilderLuc Pattyn6-Mar-16 12:49 
GeneralRe: Where can I find the code for my book? Pin
OriginalGriff6-Mar-16 22:51
mveOriginalGriff6-Mar-16 22:51 
Questionhello every one, I am begginer in webservice I have Question for you, my question is how to replace localhost with IP adress Pin
Member 121750935-Mar-16 7:25
Member 121750935-Mar-16 7:25 
QuestionRe: hello every one, I am begginer in webservice I have Question for you, my question is how to replace localhost with IP adress Pin
dan!sh 6-Mar-16 16:32
professional dan!sh 6-Mar-16 16:32 
QuestionClose Reactive extensions buffers Pin
Kenneth Haugland5-Mar-16 0:04
mvaKenneth Haugland5-Mar-16 0:04 
AnswerRe: Close Reactive extensions buffers Pin
Pete O'Hanlon6-Mar-16 20:32
mvePete O'Hanlon6-Mar-16 20:32 
GeneralRe: Close Reactive extensions buffers Pin
Kenneth Haugland6-Mar-16 22:15
mvaKenneth Haugland6-Mar-16 22:15 
QuestionWeak Event seems to fail in test method Pin
Super Lloyd4-Mar-16 17:02
Super Lloyd4-Mar-16 17:02 
EDIT this was an accidental post, problem is fixed!!

I am running / fixing all my unit test for my home made utilities.
I have a weak event build method which look like that
C#
public static PropertyChangedEventHandler AddWeakHandler<T>(this INotifyPropertyChanged model, T target, Action<T, PropertyChangedEventArgs> action)
    where T : class
{
    var weakRef = new WeakReference(target);
    PropertyChangedEventHandler handler = null;
    handler = new PropertyChangedEventHandler(
        (s, e) =>
        {
            var strongRef = weakRef.Target as T;
            if (strongRef != null)
            {
                action(strongRef, e);
            }
            else
            {
                model.PropertyChanged -= handler;
                handler = null;
            }
        });
    model.PropertyChanged += handler;
    return handler;
}
it is used like that (to show that there are no captured variable in the lambda expression
C#
public object Source
{
    get { return mSource; }
    set
    {
        var p = Property;
        if (p == null)
            value = null;
        if (value == mSource)
            return;

        if (Source is INotifyPropertyChanged)
        {
            ((INotifyPropertyChanged)Source).PropertyChanged -= previous;
            previous = null;
        }
        mSource = value;
        if (Source is INotifyPropertyChanged)
        {
            previous = WeakEvents.AddWeakHandler((INotifyPropertyChanged)Source, this, (x, arg) => x.OnSourcePropertyChanged(Source, arg));
        }
        if (p != null)
        {
            p.OnPropertyChanged();
        }
    }
}
I have a simple (XUnit) test looking like that
C#
[Fact]
   public void CheckPropertyPathIsWeakEvent()
   {
       var m = new ModelForPathCheck();
       int n = 0;
       Action<string> onChanged = s => n++;
       TriggerWeakEvent(m, onChanged, 2);

       GC.Collect();

       m.Name = "mooo";
       Assert.Equal(2, n);
   }
   [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
   static void TriggerWeakEvent(ModelForPathCheck path, Action<string> onNameChanged, int nTimeChanged)
   {
       var pv = PropertyPath.Link(path, x => x.Name, onNameChanged);
       for (int i = 0; i < nTimeChanged; i++)
           path.Name = i.ToString();
       GC.KeepAlive(pv);
   }
sadly... the count is always 3 instead of 2 (in the assert)
any idea what might have gone wrong?! Cry | :((
All in one Menu-Ribbon Bar
DirectX for WinRT/C# since 2013!
Taking over the world since 1371!


modified 5-Mar-16 21:44pm.

AnswerRe: Weak Event seems to fail in test method Pin
Kenneth Haugland4-Mar-16 23:58
mvaKenneth Haugland4-Mar-16 23:58 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 15:42
Super Lloyd5-Mar-16 15:42 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 15:43
Super Lloyd5-Mar-16 15:43 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 15:45
Super Lloyd5-Mar-16 15:45 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 17:12
Super Lloyd5-Mar-16 17:12 
GeneralRe: Weak Event seems to fail in test method Pin
Kenneth Haugland5-Mar-16 17:22
mvaKenneth Haugland5-Mar-16 17:22 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 17:28
Super Lloyd5-Mar-16 17:28 
GeneralRe: Weak Event seems to fail in test method Pin
Kenneth Haugland5-Mar-16 17:44
mvaKenneth Haugland5-Mar-16 17:44 
GeneralRe: Weak Event seems to fail in test method Pin
Super Lloyd5-Mar-16 18:11
Super Lloyd5-Mar-16 18:11 
QuestionHow to connect MySQL to dataGridView Pin
Member 122785423-Mar-16 19:48
Member 122785423-Mar-16 19:48 
AnswerRe: How to connect MySQL to dataGridView Pin
Mycroft Holmes3-Mar-16 20:34
professionalMycroft Holmes3-Mar-16 20:34 
AnswerRe: How to connect MySQL to dataGridView Pin
V.3-Mar-16 22:53
professionalV.3-Mar-16 22:53 
AnswerRe: How to connect MySQL to dataGridView Pin
Frank Kerrigan4-Mar-16 3:50
Frank Kerrigan4-Mar-16 3:50 
Questionscalar data visualization Pin
Member 123014432-Mar-16 23:12
Member 123014432-Mar-16 23:12 
AnswerRe: scalar data visualization Pin
OriginalGriff2-Mar-16 23:24
mveOriginalGriff2-Mar-16 23:24 
GeneralRe: scalar data visualization Pin
Member 123014433-Mar-16 17:49
Member 123014433-Mar-16 17:49 
AnswerRe: scalar data visualization Pin
dan!sh 3-Mar-16 18:01
professional dan!sh 3-Mar-16 18:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.