Immer "Eine Aufgabe wurde abgebrochen" beim Versuch, ein Dokument erstellen, in DocumentDB
Wenn ich versuche ein Dokument erstellen, in meinem DocumentDB-Datenbank mit dem folgenden code, der code hängt, wo ich anrufen CreateDocumentAsync() und schließlich gibt mir "Eine Aufgabe wurde abgebrochen" Fehlermeldung.
Ahnung warum?
public static async Task<Employee> CreateEmployee(Employee emp)
{
try
{
using (client = new DocumentClient(new Uri(endPointUrl), authorizationKey))
{
//Get the database
var database = await GetDatabaseAsync();
//Get the Document Collection
var collection = await GetCollectionAsync(database.SelfLink, "Employees");
await client.CreateDocumentAsync(collection.SelfLink, emp);
//Do something else with employee
}
}
catch
{
//Handle error
}
return emp;
}
P. S. Für die Kürze, ich habe nicht den code für GetDatabaseAsync() und GetCollectionsAsync() Abschnitte. Bitte beachten Sie, dass die Mitarbeiter-Dokument erstellt WIRD in meiner Datenbank. So, dieser code eindeutig Verbindung zu den DocumentDB-Datenbank, findet die Sammlung und erstellt das Dokument.
Nur nicht sicher, warum es hängt und schließlich den Fehler zurück.
***** Update ******
Hier der Fehler details:
Eine Aufgabe wurde abgebrochen.
Beschreibung: Eine nicht behandelte Ausnahme ist aufgetreten während der Ausführung der aktuellen Webanforderung. Bitte überprüfen Sie die Stapelüberwachung für weitere Informationen über den Fehler und wo Sie Ihren Ursprung in den code.
Exception Details: System.Threading.Aufgaben.TaskCanceledException: Aufgabe wurde abgebrochen.
Source Error:
HttpResponseMessage response = await client.PostAsJsonAsync("api/hr/register", employee);
Stack Trace:
[TaskCanceledException: A task was canceled.]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +10915395
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
ConsumerWebApi.Controllers.<Index>d__0.MoveNext() in c:\Users\Sam\Documents\Visual Studio 2013\Projects\ConsumerWebApi\ConsumerWebApi\Controllers\HomeController.cs:36
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +10915367
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +132
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
- Könnte Ihr Wunsch sein timing aus?
- Ich denke, das ist genau das, was passiert, aber ich verstehe nicht, warum es das timing. Warum ist es, dass die DocumentDB ist nicht mehr reagiert, obwohl das Dokument erstellt wird?
- Hey - gerade nach dem thread auf der DocumentDB MSDN-Foren (goo.gl/VZ23ls) und die anderen stackoverflow-thread (stackoverflow.com/questions/27116794/want-to-understand-async). Es klingt wie die Ausnahme stammt aus der Vermischung von synchronen und asynchronen code. Waren Sie in der Lage, dieses Problem zu beheben? Wäre schön, hier eine Antwort für andere stackoverflow-Benutzer 🙂
- Du bist genau richtig. Das problem wird verursacht, durch mein kleines Verständnis der asynchronen Programmierung! Ich poste eine Antwort. Danke für die Erinnerung!
Du musst angemeldet sein, um einen Kommentar abzugeben.
Das Problem wurde dadurch verursacht, dass nicht immer async-Anrufe direkt. Ich war der Aufruf eine asynchrone Methode, d.h. CreateDocumentAsync() falsch.
Ich habe eine separate Frage, die auf der asynchronen Programmierung und die Antworten, die ich bekam, hat mir geholfen, das Problem zu beheben. Hier der betreffende Beitrag:
Verstehen wollen async
Hatte ich einen ähnlichen Fehler geworfen und mit einer
DocumentClient
s async-Funktionen. Ich verwendetawait
richtig für jedes rufen, aber dann fand ich, dass dieses verursacht wurde durch eine proxy-server sich mit den Verkehr. Also für diejenigen, die Arbeit innerhalb des eigenen Unternehmens-Netzwerk - sollten Sie überprüfen dies.