-1

I am trying to get my program to Count how many times a certain messagebox in my program appears while it is running.

I have looked up how to do this and it seems that I will need to use int count but I'm not sure how to code this for Messageboxes as I can only find count code for strings and arrays.

4

2 回答 2

3

为 MessageBox 类创建一些静态包装类并将其计算在某种静态变量中是更好的主意。

于 2013-03-09T17:38:29.477 回答
1

有两种解决方案

1-创建一个Adapter包装MessageBox类的类,向适配器添加一个计数器字段并在每次调用中递增它

 class MyMessageBox
 {
 static int counter;

 static void Show(string msg)
 {
   counter++;
   MessageBox.Show(msg);
 }
 }

使用这种方法,您假设用户正在使用您的 MessageBox

2- 第二种解决方案是AOP
使用类似计算调用的Aspect Oriented框架PostSharpShow

于 2013-03-09T17:49:32.567 回答