简体   繁体   English

如何知道何时执行类中的方法

[英]How to know when a method in a class is being executed

I'm trying to write a log to monitor the execution time of a method for our application. 我正在尝试编写日志以监视应用程序方法的执行时间。 Is it possible to know when a method in a class is being executed without using Aspect-oriented programming. 是否可以知道何时在不使用面向方面的编程的情况下执行类中的方法。

I don't want to go into every method to write a log there so I hope someone faced this issue and can give me some suggestion. 我不想进入那里写日志的所有方法,所以我希望有人遇到这个问题并能给我一些建议。

Updated: I'm writing a SharePoint application using .Net 3.5 更新:我正在使用.Net 3.5编写SharePoint应用程序

Try using breakpoints. 尝试使用断点。 Press F10 on the space at the left side of the method, and from there, the debugging starts, where you'd be able to see value and property change after its execution. 在方法左侧的空白处按F10键,然后从那里开始调试,在调试之后,您可以在其中看到值和属性的变化。

AFAIK, without AOP or directly logging code injections the only way is a profiling API . AFAIK,没有AOP或直接记录代码注入,唯一的方法是配置API
I wouldn't choose that way for one-time task, it isn't easy. 对于一次性任务,我不会选择这种方式,这并不容易。

Addtional to @Dennis answer, I think System.Diagnostic.Debug is a choice to know when your method is executed beside Aspect-oriented programing. 除了@Dennis答案,我认为System.Diagnostic.Debug是了解何时在面向方面的编程旁边执行您的方法的选择。 However, you need to turn on Debug build flag, or supplying argument in csc.exe 但是,您需要打开Debug build标志,或在csc.exe中提供参数。

/define:DEBUG 

in sp 2010 you can turn on developer dashboard (on dev stage only for safety) this will give you abreakdown of calls and times 在sp 2010中,您可以打开开发人员仪表板(仅出于安全起见仅在开发阶段),这将使您可以减少通话次数和时间

http://msdn.microsoft.com/en-us/library/gg512103(v=office.14).aspx http://msdn.microsoft.com/en-us/library/gg512103(v=office.14).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么知道何时创建进程并停止执行该进程或在Windows中终止该进程? - How can i know when a process is being created and stop it from being executed or terminated it in windows? OwinStartup 类中的 Configuration 方法如何以及何时被调用/执行? - How and when does Configuration method in OwinStartup class is called/executed? OWIN Startup类与WebAPIConfig.Register方法一起执行 - OWIN Startup class is being executed along with WebAPIConfig.Register method 从 Postman 调用时未执行 API 方法 - API Method not being executed when called from Postman 如何在类中保存一个方法以便稍后执行 - How to save a method in a class to be executed later 订阅正在执行的任何方法 - Subscribe to whatever method is being executed Windows:如何知道文件何时被复制、下载或执行? - Windows: How to know when a file is copied, downloaded or executed? 单元测试在事件触发时在类上执行void方法 - Unit test that a void method on a class is executed when an event fires 如何指出项目中要在类库组件中执行的方法 - How to point out to a method in project to be executed inside a class library component 如何知道控制器中的方法何时完成 - How to know when a method finish in controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM