How to find all methods currently subscribed to an event in WPF / C# during debugging in Visual Studio
I am quite new to WPF and rather new to C# and now have inherited a C#/WPF App with over 60k lines of code (no MVVM was used, the design pattern is rather improvised). Now, I have to change a rather small thing in the UI, but this control is quite crucial and therefore heavily woven into the whole solution. I know the "Live Visual Tree" Function in Visual Studio and also I know the Live Property Explorer. However, I would like to have something like a "Live EVENT Explorer" to see what methods are registered to an event of this control. I would like to have something like:
a) A possibility to see, what methods are currently subscribed to a certain event (for example the SelectionChanged event of a ListView). With "currently" I mean, that the subscribed methods are changing quite a lot depending on what radio buttons and check boxes are selected, etc. So I would like to make all the selections I need and then inspect the control and see what methods are subscribed to one of its events.
b) A possibility to stop right in the first method that is being triggered by this event if I for example change the selection in my control. So that I can step through all the following code?
Does anyone of you have an idea if either one of this is possible with a built-in function in Visual Studio and also how to do it? Or is there maybe another tool out there how to achieve something like this?
c# wpf debugging visual-studio-debugging
add a comment |
I am quite new to WPF and rather new to C# and now have inherited a C#/WPF App with over 60k lines of code (no MVVM was used, the design pattern is rather improvised). Now, I have to change a rather small thing in the UI, but this control is quite crucial and therefore heavily woven into the whole solution. I know the "Live Visual Tree" Function in Visual Studio and also I know the Live Property Explorer. However, I would like to have something like a "Live EVENT Explorer" to see what methods are registered to an event of this control. I would like to have something like:
a) A possibility to see, what methods are currently subscribed to a certain event (for example the SelectionChanged event of a ListView). With "currently" I mean, that the subscribed methods are changing quite a lot depending on what radio buttons and check boxes are selected, etc. So I would like to make all the selections I need and then inspect the control and see what methods are subscribed to one of its events.
b) A possibility to stop right in the first method that is being triggered by this event if I for example change the selection in my control. So that I can step through all the following code?
Does anyone of you have an idea if either one of this is possible with a built-in function in Visual Studio and also how to do it? Or is there maybe another tool out there how to achieve something like this?
c# wpf debugging visual-studio-debugging
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09
add a comment |
I am quite new to WPF and rather new to C# and now have inherited a C#/WPF App with over 60k lines of code (no MVVM was used, the design pattern is rather improvised). Now, I have to change a rather small thing in the UI, but this control is quite crucial and therefore heavily woven into the whole solution. I know the "Live Visual Tree" Function in Visual Studio and also I know the Live Property Explorer. However, I would like to have something like a "Live EVENT Explorer" to see what methods are registered to an event of this control. I would like to have something like:
a) A possibility to see, what methods are currently subscribed to a certain event (for example the SelectionChanged event of a ListView). With "currently" I mean, that the subscribed methods are changing quite a lot depending on what radio buttons and check boxes are selected, etc. So I would like to make all the selections I need and then inspect the control and see what methods are subscribed to one of its events.
b) A possibility to stop right in the first method that is being triggered by this event if I for example change the selection in my control. So that I can step through all the following code?
Does anyone of you have an idea if either one of this is possible with a built-in function in Visual Studio and also how to do it? Or is there maybe another tool out there how to achieve something like this?
c# wpf debugging visual-studio-debugging
I am quite new to WPF and rather new to C# and now have inherited a C#/WPF App with over 60k lines of code (no MVVM was used, the design pattern is rather improvised). Now, I have to change a rather small thing in the UI, but this control is quite crucial and therefore heavily woven into the whole solution. I know the "Live Visual Tree" Function in Visual Studio and also I know the Live Property Explorer. However, I would like to have something like a "Live EVENT Explorer" to see what methods are registered to an event of this control. I would like to have something like:
a) A possibility to see, what methods are currently subscribed to a certain event (for example the SelectionChanged event of a ListView). With "currently" I mean, that the subscribed methods are changing quite a lot depending on what radio buttons and check boxes are selected, etc. So I would like to make all the selections I need and then inspect the control and see what methods are subscribed to one of its events.
b) A possibility to stop right in the first method that is being triggered by this event if I for example change the selection in my control. So that I can step through all the following code?
Does anyone of you have an idea if either one of this is possible with a built-in function in Visual Studio and also how to do it? Or is there maybe another tool out there how to achieve something like this?
c# wpf debugging visual-studio-debugging
c# wpf debugging visual-studio-debugging
edited Nov 12 at 15:25
asked Nov 12 at 15:02
WurzelseppQX
272213
272213
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09
add a comment |
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09
add a comment |
2 Answers
2
active
oldest
votes
In most cases, Find All References should have it covered, but this fails when the event is not unique enough (imagine Button.Click).
You can access this in a debugger by browsing to the event object and examining the _invocationList
field. If this field is not populated, look at _methodPtr
field. If both fields are null, then no one is subscribed.
_target
is the object containing the subscribed method. If it is null, a static method is subscribed (which makes identification much more tricky). Otherwise, you can dump the method table of the target object to find the subscribed method.
In Visual studio, the debug tooltips make this easy. For a unicast delegate, hovering over the event shows the declaring type and method name (and arity if needed):
for multicast, the _invocationList
takes over:
add a comment |
You can go to the View
where the ListView
is, and in code-behind, subscribe your self to the ListView.SelectionChanged
event and add the following code on the handling of the event:
foreach(EventHandler subscriber in ListView.SelectionChanged.GetInvocationList())
{
// etc
}
You can get more info from here:
How do I get the subscribers of an event?
I hope that helps you a bit to debug it.
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264861%2fhow-to-find-all-methods-currently-subscribed-to-an-event-in-wpf-c-sharp-during%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In most cases, Find All References should have it covered, but this fails when the event is not unique enough (imagine Button.Click).
You can access this in a debugger by browsing to the event object and examining the _invocationList
field. If this field is not populated, look at _methodPtr
field. If both fields are null, then no one is subscribed.
_target
is the object containing the subscribed method. If it is null, a static method is subscribed (which makes identification much more tricky). Otherwise, you can dump the method table of the target object to find the subscribed method.
In Visual studio, the debug tooltips make this easy. For a unicast delegate, hovering over the event shows the declaring type and method name (and arity if needed):
for multicast, the _invocationList
takes over:
add a comment |
In most cases, Find All References should have it covered, but this fails when the event is not unique enough (imagine Button.Click).
You can access this in a debugger by browsing to the event object and examining the _invocationList
field. If this field is not populated, look at _methodPtr
field. If both fields are null, then no one is subscribed.
_target
is the object containing the subscribed method. If it is null, a static method is subscribed (which makes identification much more tricky). Otherwise, you can dump the method table of the target object to find the subscribed method.
In Visual studio, the debug tooltips make this easy. For a unicast delegate, hovering over the event shows the declaring type and method name (and arity if needed):
for multicast, the _invocationList
takes over:
add a comment |
In most cases, Find All References should have it covered, but this fails when the event is not unique enough (imagine Button.Click).
You can access this in a debugger by browsing to the event object and examining the _invocationList
field. If this field is not populated, look at _methodPtr
field. If both fields are null, then no one is subscribed.
_target
is the object containing the subscribed method. If it is null, a static method is subscribed (which makes identification much more tricky). Otherwise, you can dump the method table of the target object to find the subscribed method.
In Visual studio, the debug tooltips make this easy. For a unicast delegate, hovering over the event shows the declaring type and method name (and arity if needed):
for multicast, the _invocationList
takes over:
In most cases, Find All References should have it covered, but this fails when the event is not unique enough (imagine Button.Click).
You can access this in a debugger by browsing to the event object and examining the _invocationList
field. If this field is not populated, look at _methodPtr
field. If both fields are null, then no one is subscribed.
_target
is the object containing the subscribed method. If it is null, a static method is subscribed (which makes identification much more tricky). Otherwise, you can dump the method table of the target object to find the subscribed method.
In Visual studio, the debug tooltips make this easy. For a unicast delegate, hovering over the event shows the declaring type and method name (and arity if needed):
for multicast, the _invocationList
takes over:
edited Nov 13 at 20:37
answered Nov 12 at 15:30
Mitch
14.6k33663
14.6k33663
add a comment |
add a comment |
You can go to the View
where the ListView
is, and in code-behind, subscribe your self to the ListView.SelectionChanged
event and add the following code on the handling of the event:
foreach(EventHandler subscriber in ListView.SelectionChanged.GetInvocationList())
{
// etc
}
You can get more info from here:
How do I get the subscribers of an event?
I hope that helps you a bit to debug it.
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
add a comment |
You can go to the View
where the ListView
is, and in code-behind, subscribe your self to the ListView.SelectionChanged
event and add the following code on the handling of the event:
foreach(EventHandler subscriber in ListView.SelectionChanged.GetInvocationList())
{
// etc
}
You can get more info from here:
How do I get the subscribers of an event?
I hope that helps you a bit to debug it.
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
add a comment |
You can go to the View
where the ListView
is, and in code-behind, subscribe your self to the ListView.SelectionChanged
event and add the following code on the handling of the event:
foreach(EventHandler subscriber in ListView.SelectionChanged.GetInvocationList())
{
// etc
}
You can get more info from here:
How do I get the subscribers of an event?
I hope that helps you a bit to debug it.
You can go to the View
where the ListView
is, and in code-behind, subscribe your self to the ListView.SelectionChanged
event and add the following code on the handling of the event:
foreach(EventHandler subscriber in ListView.SelectionChanged.GetInvocationList())
{
// etc
}
You can get more info from here:
How do I get the subscribers of an event?
I hope that helps you a bit to debug it.
answered Nov 12 at 15:17
Nekeniehl
553420
553420
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
add a comment |
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
I will try that, however I hoped to have somehow a built-in function of VS or another tool that does not need some additional code (as I would have this case for many events). But for a single event, this is a nice solution.
– WurzelseppQX
Nov 12 at 15:24
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
AFAIK there is non build-in function or external tool to get the subscribers of an event without stoping the execution and debuggint it.
– Nekeniehl
Nov 12 at 15:27
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
After further investigation, I use a tool wich I didnt know you can check the events and by whom was handled it. Check SnoopWpf -> github.com/cplotts/snoopwpf/releases
– Nekeniehl
Nov 14 at 10:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264861%2fhow-to-find-all-methods-currently-subscribed-to-an-event-in-wpf-c-sharp-during%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you using MVVM?
– Nekeniehl
Nov 12 at 15:11
Good question. This I should have mentioned. No MVVM was used. The design pattern is rather "improvised". Also the colleague who wrote most of it is not in the company anymore.
– WurzelseppQX
Nov 12 at 15:13
See stackoverflow.com/questions/1191433/… and stackoverflow.com/questions/3978364/….
– Sergey Vlasov
Nov 13 at 3:26
Any update for this issue? Have you resolved this issue? Does the answers below solve your problem??
– Alex
Nov 15 at 1:17
After some testing, the answer of Mitch fits my question best, but also the answer of Nekeniehl is a good one (i.e. combined with #IF Debug preprocessor instruction), depending on the situation. Also his comment about the Snoop Tool helped me a lot (in general). With all the answers and comments, I figured out a way of working which is fine for me for the moment. But originally I hoped that there was maybe a kind of tool where I can just inspect a WPF control and see all methods subscribed to an event, similar to Live Property viewer. But such a tools seems not to exist yet.
– WurzelseppQX
Nov 15 at 8:09