Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
GeneralRe: User names can contain only alphabates Pin
Tarun.K.S20-Apr-11 7:21
Tarun.K.S20-Apr-11 7:21 
AnswerRe: User names can contain only alphabates Pin
DaveyM6920-Apr-11 7:11
professionalDaveyM6920-Apr-11 7:11 
Questionget an indication when a control added to a pnel in CF 3.5 Pin
prasadbuddhika20-Apr-11 1:07
prasadbuddhika20-Apr-11 1:07 
AnswerRe: get an indication when a control added to a pnel in CF 3.5 Pin
Luc Pattyn20-Apr-11 1:13
sitebuilderLuc Pattyn20-Apr-11 1:13 
QuestionLists should not accept duplicate user names. Pin
DivyaReddyM20-Apr-11 0:50
DivyaReddyM20-Apr-11 0:50 
AnswerRe: Lists should not accept duplicate user names. Pin
Wayne Gaylard20-Apr-11 1:06
professionalWayne Gaylard20-Apr-11 1:06 
AnswerRe: Lists should not accept duplicate user names. Pin
John-ph20-Apr-11 1:09
John-ph20-Apr-11 1:09 
GeneralRe: Lists should not accept duplicate user names. Pin
DivyaReddyM20-Apr-11 1:23
DivyaReddyM20-Apr-11 1:23 
GeneralRe: Lists should not accept duplicate user names. Pin
Alan Balkany20-Apr-11 3:52
Alan Balkany20-Apr-11 3:52 
GeneralRe: Lists should not accept duplicate user names. Pin
Prasanta_Prince20-Apr-11 21:58
Prasanta_Prince20-Apr-11 21:58 
QuestionSendMessage API and WM_PASTE Pin
John-ph19-Apr-11 19:20
John-ph19-Apr-11 19:20 
AnswerRe: SendMessage API and WM_PASTE Pin
John-ph19-Apr-11 22:43
John-ph19-Apr-11 22:43 
AnswerRe: SendMessage API and WM_PASTE Pin
John-ph20-Apr-11 0:23
John-ph20-Apr-11 0:23 
QuestionSmart Card ACOS3-24 1.07.18 [modified] Pin
Ari Astika19-Apr-11 17:41
Ari Astika19-Apr-11 17:41 
AnswerRe: Smart Card ACOS3-24 1.07.18 Pin
OriginalGriff19-Apr-11 21:18
mveOriginalGriff19-Apr-11 21:18 
GeneralRe: Smart Card ACOS3-24 1.07.18 Pin
Ari Astika19-Apr-11 21:30
Ari Astika19-Apr-11 21:30 
GeneralRe: Smart Card ACOS3-24 1.07.18 Pin
OriginalGriff19-Apr-11 21:35
mveOriginalGriff19-Apr-11 21:35 
GeneralRe: Smart Card ACOS3-24 1.07.18 Pin
Ari Astika19-Apr-11 21:39
Ari Astika19-Apr-11 21:39 
QuestionQuestion about Weak Events... Pin
SledgeHammer0119-Apr-11 7:51
SledgeHammer0119-Apr-11 7:51 
I have a class:

public class SomeClass<t> : ISomeInterfaceBase
{
.
.
public delegate void MessageHandler(object sender, T message);

public event MessageHandler Handler
{
}
.
.
}

so its a generic class and has a delegate that uses the T type as a param. I thought that was a good idea so users don't have to cast to their T type.

But an issue arose:

MainWindow -> subscribes to the event
MainWindow pops up Window1
Window1 -> subscribes to the event too
Window1 closes (and doesn't unsubscribe)

Now when the event triggers, it still calls the one in Window1 too.

So I figured I'd use weak references.

public event MessageHandler Handler
{
add
{
lock (_lstHandlers)
{
foreach (WeakReference weakRef in _lstHandlers)
{
if ((MessageHandler)(weakRef.Target) == value)
return;
}

_lstHandlers.Add(new WeakReference(value));
}
}

when the event needs to be triggered, I loop through _lstHandlers and check if isAlive = true and then send it, otherwise, I remove that event.

Problem is, isAlive never goes false when I close window1.

I looked into WeakEventManager, but that doesn't seem like it will jive with a generic delegate. Seems like you need to have a WeakEventManager for every generic type thats created?
AnswerRe: Question about Weak Events... Pin
David198719-Apr-11 7:58
David198719-Apr-11 7:58 
GeneralRe: Question about Weak Events... Pin
SledgeHammer0119-Apr-11 8:05
SledgeHammer0119-Apr-11 8:05 
GeneralRe: Question about Weak Events... Pin
David198719-Apr-11 8:32
David198719-Apr-11 8:32 
AnswerRe: Question about Weak Events... Pin
DaveyM6919-Apr-11 8:42
professionalDaveyM6919-Apr-11 8:42 
GeneralRe: Question about Weak Events... Pin
SledgeHammer0119-Apr-11 10:06
SledgeHammer0119-Apr-11 10:06 
GeneralRe: Question about Weak Events... Pin
DaveyM6919-Apr-11 12:13
professionalDaveyM6919-Apr-11 12:13 

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.