Share via

Need help on using weakreferences.

Sunil A M 171 Reputation points
2023-07-17T16:45:59.7933333+00:00

Hi Team,

I have received an answer for my one of the question(below is the link).

https://learn.microsoft.com/en-us/answers/questions/1320983/need-notification-for-all-the-consumers-when-there

I need help here on the code which is written in the above link, i need to implement a weak reference(whoever uses get and set method) and also i need to know how to do a call back (invoke callbackOnSettingChanged in NotifySettingChanged method).

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,086 Reputation points
    2023-07-17T17:27:29.1533333+00:00

    you just define a delegate and invoke in the notify routine:

    https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/how-to-declare-instantiate-and-use-a-delegate

    not sure your use of weak reference. typically used with a cache. maybe you wanted weak delegate:

    https://learn.microsoft.com/en-us/previous-versions/windows/embedded/cc533276(v=msdn.10)

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.