PC Review


Reply
Thread Tools Rate Thread

How to invoke methods from a SyncProcessMessage?

 
 
=?Utf-8?B?TWFydGluUGFyw6k=?=
Guest
Posts: n/a
 
      4th Apr 2006
Hi,
I am working on a project and I ran into a little nag! I am writting a
set of custom attributes ,
[PreProcess(Type, aMethod)]
and [PostProcess(Type, aMethod)].
The goal here is to put these attributes on methods so that before the
method is executed the [PreProcess] method is executed and once the method
is
completed the [PostProcess] is executed.

public class JustSomeClass : ContextBoundObject
{
[PreProcess( typeof(AnotherClass), "PreCondition" )
[PostProcess( typeof(AnotherClass), "PostCondition" )
public void SomeMethod()
{
}
}

That would turn out that when JustSomeClass.SomeMethod() is called, we would
call AnotherClass.PreCondition and once completed we would call
AnotherClass.PostCondition.

I have managed to get this to work, here is waht my sink looks like:

public IMessage SyncProcessMessage( IMessage msg )
{
IMessage returnMessage = null;

// Process the Pre-Condition on the method
PreProcess( msg );

// Execute the method
returnMessage = _nextSink.SyncProcessMessage( msg );

// Process the Post-Condition on the method
returnMessage = PostProcess( returnMessage );

return returnMessage;
}


But I have some nagging little issues to resolve.
#1 - If my Pre-Condition also has [PreProcess()] and [PostProcess()], they
are not called. Seems like my sink is ignored. The same goes for my
PostCondition.
#2 - If my PreCondition sets uses CallContext.SetData() to set store some
data in the logical thread, it gets lost: meaning when I try to retrieve it
I
get a null. This will only happen if the object that I try to set derives
from ILogicalThreadAffinative .


I think that both issues come from the way that I call the PreProcess and
PostProcess. When I need to call PreProcess I create an instance of the
object like so:
Object classObject = Activator.CreateInstance( ClassType );
then I call the method
m_classType.InvokeMember( m_methodName,
BindingFlags.Default |
BindingFlags.InvokeMethod,
null,
classObject,
null );

Since all PreProcess and PostProcess ahve the same signature, this is easy.


Finally my question:
How can I call my PreProcess and PostProcess method in order to get their
own PreProcess and POstProcess attributes evaluated? I see a lot of
documentation about processing messages, but I don't understand how I could
invoke these methods using messages.

Thank you!

--
(E-Mail Removed)am
Martin Paré :-)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invoke methods with params codefragment@googlemail.com Microsoft C# .NET 7 23rd Apr 2008 11:08 PM
Control.Invoke and anonymous methods Lee Crabtree Microsoft Dot NET Framework Forms 1 27th Aug 2007 12:33 AM
Reflection: invoke some methods through TransparentProxy enrico.gobbo@seait.it Microsoft Dot NET Framework 0 9th Aug 2007 04:23 PM
invoke framework 2.0 methods from 1.1 ginkim@gmail.com Microsoft ASP .NET 1 30th Jan 2007 09:03 PM
Asynchronous methods, Invoke Christian Westerlund Microsoft Dot NET Compact Framework 4 17th Mar 2004 01:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:02 PM.