What is the Result of this assignment (Execute.OnUIThread)

Topics: Framework Services
Mar 29, 2012 at 11:16 PM

I am working my way through the bowels of Caliburn.Micro and came across this statement.

EventAggregator.DefaultPublicationThreadMarshaller = Execute.OnUIThread;

This method seems to be an extension method that returns void and the DefaultPublicationThreadMarshaller is of type Action. What is the result of this assignment?



Mar 30, 2012 at 8:51 AM

My initial thought is you are assigning the actual function OnUIThread to DefaultPublicationThreadMarshaller...

Mar 30, 2012 at 9:03 AM

If you know what a delegate is (or alternatively a function pointer), the code above stores a pointer to the Execute.UI function into the EventAggregator.DefaultPublicationThreadMarshaler... in other words, every time the code calls the marshaller, it is implicitly calling the Execute.OnUIThread. This technique is often used in Caliburn.Micro to provide extensibility over static classes.

Mar 30, 2012 at 9:12 AM

That was my thinking but I wanted to double check, thanks a mill!