Es gibt keine Unterschiede, wie die BeginInvoke
Methode eine private LegacyBeginInvokeImpl
Methode aufruft, die itslef die private Methode ruft InvokeAsyncImpl
(die Methode von InvokeAsync
). Es ist also im Grunde dasselbe. Es scheint, als wäre es ein einfaches Refactoring, aber es ist seltsam, dass die Methoden BeginInvoke
nicht als veraltet markiert wurden.
BeginInvoke:
public DispatcherOperation BeginInvoke(DispatcherPriority priority, Delegate method)
{
return this.LegacyBeginInvokeImpl(priority, method, null, 0);
}
private DispatcherOperation LegacyBeginInvokeImpl(DispatcherPriority priority, Delegate method, object args, int numArgs)
{
Dispatcher.ValidatePriority(priority, "priority");
if (method == null)
{
throw new ArgumentNullException("method");
}
DispatcherOperation dispatcherOperation = new DispatcherOperation(this, method, priority, args, numArgs);
this.InvokeAsyncImpl(dispatcherOperation, CancellationToken.None);
return dispatcherOperation;
}
InvokeAsync:
public DispatcherOperation InvokeAsync(Action callback, DispatcherPriority priority)
{
return this.InvokeAsync(callback, priority, CancellationToken.None);
}
public DispatcherOperation InvokeAsync(Action callback, DispatcherPriority priority, CancellationToken cancellationToken)
{
if (callback == null)
{
throw new ArgumentNullException("callback");
}
Dispatcher.ValidatePriority(priority, "priority");
DispatcherOperation dispatcherOperation = new DispatcherOperation(this, priority, callback);
this.InvokeAsyncImpl(dispatcherOperation, cancellationToken);
return dispatcherOperation;
}
Zur Zeit bekomme ich unbehandelte Ausnahmen wie erwartet mit BeginInvoke (sowohl DispatcherUnh andledException für den Dispatcher und AppDomain.CurrentDomain.UnhandledException), aber nicht behandelte Ausnahmen in InvokeAsync werden stillschweigend verschluckt. Wenn Sie die Aufgabe von InvokeAsync mit einer Ausnahmefunktion ausführen, scheint dies ein gültiges Problem zu sein. – Lamarth
'BeginInvoke' ist nach dem [" Asynchronous Programming Model "] (https://msdn.microsoft.com/en-us/library/ms228963 (v = vs.110) .aspx) in .NET, das' BeginSomething verwendet 'und' EndSomething' Methoden für asynchrone Operationen. Vermutlich wurde dies deshalb nicht als veraltet oder veraltet bezeichnet. Abgesehen davon, dass die 'Begin' /' End'-Konvention für die Verwendung von 'IAsyncResult' gedacht ist, und' BeginInvoke' nicht, gibt es auch kein 'EndInvoke', so dass es an erster Stelle überflüssig war. – sidbushes