Monday, 15 April 2013

c# - Where are CLR-defined methods like [delegate].BeginInvoke documented? -



c# - Where are CLR-defined methods like [delegate].BeginInvoke documented? -

[edit, rephrased:] seems question poorly worded indeed, , poorly received too. hope finish rephrasing helps...

msdn tells specifies: control.begininvoke() executes delegate on thread control's handle created on, gui thread. , dispatcher.begininvoke() run on thread dispatcher object created. thread created me.

but delegates "the clr automatically defines begininvoke , endinvoke" , these calls run on threadpool-thread instead. apart surprising different behaviour wonder how can find specs of functions automatically implemented.

for example: intelli-sense shows delegate has dynamicinvoke(). class system.delegate{} have dynamicinvoke() might imply delegate inherits it. delegate{} has no begininvoke(). , delegate{} has several functions delegate has not. delegate gets getobjectdata() method. , seems come iserializable.

so in conclusion, delegate appears gets methods (1) clr "automatically", (2) subset of delegate{} perchance multicastdelegate{}, , perchance (3) iserializble. where can find comprehensive specification of methods delegate gets? interesting begininvoke(), , it's exact signature, 2 aforementioned methods name have different sets of signatures.

[someone suggested in edit "delegate" "delegate". daresay, not.]

thanks

the control.begin/end/invoke() , dispatcher.begin/end/invoke() methods have identical names , similar behavior delegate's begin/end/invoke() methods best scrap thought same. of import difference delegate's methods type-safe, that's missing command , dispatcher versions. runtime behavior different well.

the rules rule delegate spelled out in detail in cli spec, ecma 335, chapter ii.14.6. best read chapter, i'll give synopsis.

a delegate declaration transformed class inherits multicastdelegate (not delegate specified in cli spec). class has 4 members, runtime implementation provided clr:

a constructor takes object , intptr. object delegate.target, intptr address of target method, delegate.method. these members used later when invoke delegate, target property supplies this reference if method delegate bound instance method, null static method. method property determines method gets invoked. don't specify these arguments directly, compiler supplies them when utilize new operator or subscribe event handler += operator. lots of syntax sugar in case of events, don't have utilize new operator explicitly.

an invoke() method. arguments of method dynamically generated , match delegate declaration. calling invoke() method runs delegate target method on same thread, synchronous call. utilize in c#, utilize syntax sugar allows delegate object invoked using object name, followed parentheses.

a begininvoke() method, provides way create asynchronous call. method completes while target method busy executing, similar threadpool.queueuserworkitem type-safe arguments. homecoming type system.iasyncresult, used find out when asynchronous phone call completed , supplied endinvoke() method. first argument optional system.asynccallback delegate object, it's target automatically called when asynchronous phone call complete. sec argument optional object, passed as-is callback, useful maintain track of state. additional arguments dynamically generated , match delegate declaration.

an endinvoke() method. takes single argument of type iasyncresult, must pass 1 got begininvoke(). completes asynchronous phone call , releases resources.

any additional methods see on delegate object ones inherited base of operations classes, multicastdelegate , delegate. dynamicinvoke() , getobjectdata().

asynchronous calls tricky ones , need utilize them. in fact not available in silverlight. delegate target method runs on arbitrary thread-pool thread. unhandled exception might throw captured , terminates thread not program. must phone call endinvoke(), not doing cause resource leak 10 minutes. if target method threw exception re-raised when phone call endinvoke(). have no command on thread-pool thread, there no way cancel or abort it. task or thread classes improve alternatives.

msdn relevant, methods of delegate type not documented. assumes know , specification , delegate declaration.

c# documentation msdn begininvoke

No comments:

Post a Comment