Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Monitoring all the events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nash - 24 Jan 2008 09:39 GMT
Dear All,
I am beginner in C#. I am writing an application which will monitor
for all the events that are generated in my application and log it in
a file. Is there any way to put a hook on message queue and achieve
that or is there by any means i can subscribe my method to respond to
all the events and then calling appropriate functions?

Thanks in advance.
Alberto Poblacion - 24 Jan 2008 10:24 GMT
> I am beginner in C#. I am writing an application which will monitor
> for all the events that are generated in my application and log it in
> a file. Is there any way to put a hook on message queue and achieve
> that or is there by any means i can subscribe my method to respond to
> all the events and then calling appropriate functions?

  You can hook the message queue with
  System.Windows.Forms.Application.AddMessageFilter(new MyFilter());
  Where MyFilter should implement IMessageFilter, which has a method
"PreFilterMessage" that will give you the windows messages. Note that there
is a huge number of messages going through this, so if you try to log them
all you are probably going to be overflowed.

  If you want to capture all the Events raised by the Form object, you can
just double-click on each of them in the events window in the Designer. This
will create a method for each of the events in your form.cs. You can then
copy and paste a call to your logging routine inside each of these methods.
This is not very pretty, but is much easier to do than trying to use
Reflection to enumerate all of the events and hooking them on-the-fly.
Nash - 24 Jan 2008 10:39 GMT
On Jan 24, 3:24 pm, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.org> wrote:

> > I am beginner in C#. I am writing an application which will monitor
> > for all the events that are generated in my application and log it in
[quoted text clipped - 15 lines]
> This is not very pretty, but is much easier to do than trying to use
> Reflection to enumerate all of the events and hooking them on-the-fly.

Dear Alberto,
Thanks for your response. your first approach seems intresting
because later if i add another control to the form i dont need to put
my logging routine inside that event handler. I am right now intrested
in loging Button Click only. But i have one question suppose if i am
having a button and its event handler in the class and i am doing the
hook also. Will PreFilterMessage and MyEventHanlder will get called?
Alberto Poblacion - 24 Jan 2008 11:13 GMT
> [...] I am right now intrested
> in loging Button Click only. But i have one question suppose if i am
> having a button and its event handler in the class and i am doing the
> hook also. Will PreFilterMessage and MyEventHanlder will get called?

   Yes. PreFilterMessage will be called first. Here you can examine the
message, and possibly cancel it. If you don't cancel the message, it will
reach the Form class, which will send it to the Button object, and the
Button will in turn raise its Click event, which will then call your
MyEventHanlder.
Nash - 25 Jan 2008 11:16 GMT
On Jan 24, 4:13 pm, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.org> wrote:

> > [...] I am right now intrested
> > in loging Button Click only. But i have one question suppose if i am
[quoted text clipped - 6 lines]
> Button will in turn raise its Click event, which will then call your
> MyEventHanlder.

thanks alberto it really helped me.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.