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.
It is better idea to make some static wrapper class for MessageBox class and count it there in some kind of static variable.
There are two solutions for this
1- create a class Adapter
that wraps MessageBox
class, add a counter field to the Adapter and increment it in every call
class MyMessageBox
{
static int counter;
static void Show(string msg)
{
counter++;
MessageBox.Show(msg);
}
}
using this approach you assume that users are using your MessageBox
2- The second solution is AOP
use an Aspect Oriented
framework like PostSharp
to count Show
calls