Anyone know why Delegate.BeginInvoke isn't supported on Silverlight?
The MSDN docs state:
In Silverlight, the BeginInvoke method that is automatically defined on all delegate types always thro开发者_StackOverflow中文版ws a NotSupportedException, so you cannot use it to make asynchronous method calls on thread pool threads.
But doesn't state why.
Anyone have an idea?
Complex question.
All BeginInvoke method declarations for delegates looks like
[MethodImpl(0, MethodCodeType=MethodCodeType.Runtime)]
public virtual IAsyncResult BeginInvoke(...some params...);
Most important part here is MethodCodeType.Runtime. It
Specifies that the method implementation is provided by the runtime.
More about runtime implementation you may read in this pretty old but still actual article.
Silverlight is cross platform framework. So it should implement its own platform independent (i.e. managed) mechanism of asynchronous execution (threading and dispatching). So that's the story of managed Deployment.Current.Dispatcher class and its BeginInvoke method which might be called from Silverlight.
BTW both Dispatcher and DispatcherOperation classes are CLS compliant that guarantees they work at different CLI implementations. So the short answer to question
why Delegate.BeginInvoke isn't supported on Silverlight?
is because it's time to create REALLY cross platform applications :)
精彩评论