2014-07-14 9 views
19

Getting System.ArgumentException - Utilizzo del valore di parola chiave non definito 1 per l'evento TaskScheduled in asis asincroni.ArgumentException - Utilizzo del valore di parola chiave non definito 1 per l'evento TaskScheduled in async

C'è qualcosa che non va quando si esegue la prima istruzione attendono in un app universale con Visual Studio 2013 Aggiornamento 3.

Sto usando WP8.1 universale e applicazioni Silverlight dopo aver installato Visual Studio 2013 Aggiornamento 3.

Le eccezioni si verificano nelle modalità Emulatore/Dispositivo. Ho trascorso un paio di giorni a cercare questo problema senza alcuna soluzione.

Ho un articolo di pari livello nel forum di Windows Dev Center ma non ho ricevuto alcuna risposta da Microsoft.

Il codice è semplice. Una volta generata l'eccezione interna, l'attesa non ritorna mai.

Qualcun altro ha questi problemi con async ?? risoluzione?

public async Task<StorageFolder> FolderExists(StorageFolder parent, string folderName) 
{ 
    StorageFolder result = null; 
    try 
    { 
     // Exception happens here. The code never returns so the thread hangs 
     result = await parent.GetFolderAsync(folderName); 
    } 
    catch (Exception ex) 
    { 
     if (FeishLogger.Logger.IsDebug) 
      ex.LogException(() => string.Format("FolderExists File: {0}\\{1}", parent.Path, folderName)); 
    } 

    return result; 
} 

eccezione completa:

System.ArgumentException occurred 
    _HResult=-2147024809 
    _message=Use of undefined keyword value 1 for event TaskScheduled. 
    HResult=-2147024809 
    IsTransient=false 
    Message=Use of undefined keyword value 1 for event TaskScheduled. 
    Source=mscorlib 
    StackTrace: 
     at System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UInt64 keywords, String eventName) 
    InnerException: 

Ho un progetto di esempio disponibili. La creazione di un'app universale per shell e l'aggiunta di alcune istruzioni di attesa rendono il problema rielaborato.

private async Task AsyncMethod() 
{ 
    Debug.WriteLine("({0:0000} - Sync Debug)", Environment.CurrentManagedThreadId); 

    // Uncomment this line to make it work 
    //await Task.Delay(1); 

    // Fails only if the line above is commented 
    await Task.Run(() => Debug.WriteLine("({0:0000} - Async Debug)", Environment.CurrentManagedThreadId)); 
} 

VS error

Ecco il codice OnLaunched completo con le chiamate a AsyncMethod

protected override async void OnLaunched(LaunchActivatedEventArgs e) 
    { 
     #if DEBUG 
     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      this.DebugSettings.EnableFrameRateCounter = true; 
     } 
     #endif 

     Frame rootFrame = Window.Current.Content as Frame; 

     // Do not repeat app initialization when the Window already has content, 
     // just ensure that the window is active 
     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 

      // TODO: change this value to a cache size that is appropriate for your application 
      rootFrame.CacheSize = 1; 

      if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       // TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     if (rootFrame.Content == null) 
     { 
     #if WINDOWS_PHONE_APP 
      // Removes the turnstile navigation for startup. 
      if (rootFrame.ContentTransitions != null) 
      { 
       this.transitions = new TransitionCollection(); 
       foreach (var c in rootFrame.ContentTransitions) 
       { 
        this.transitions.Add(c); 
       } 
      } 

      rootFrame.ContentTransitions = null; 
      rootFrame.Navigated += this.RootFrame_FirstNavigated; 
     #endif 

      await AsyncMethod(); 

      await AsyncMethods(); 
      await AsyncMethods(); 
      await AsyncMethods(); 


      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      if (!rootFrame.Navigate(typeof(MainPage), e.Arguments)) 
      { 
       throw new Exception("Failed to create initial page"); 
      } 
     } 

     // Ensure the current window is active 
     Window.Current.Activate(); 
    } 
+0

Ho rimosso e reinstallato gli SDK di Windows Phone, gli emulatori e Visual Studio. Dopo aver reinstallato tutto il problema persiste !! per favore aiuto –

+0

Ho riscontrato lo stesso problema - hai risolto? –

+1

C'è un buco nel forum MSDN: [Hack workaround finché Microsoft non lo risolve] (http://social.msdn.microsoft.com/Forum/windowsapps/it-IT/3e505e04-7f30-4313-aa47-275eaef333dd/systemargumentexception-uso-di-undefined-parola chiave-valore-1-per-evento-taskscheduled-in-async? forum = wpdevelop) –

risposta

5

L'eccezione può essere ignorato. Basta premere play. In alternativa è possibile disabilitare l'interruzione delle eccezioni nel menu debug -> eccezioni.

enter image description here

+0

Perché si verifica in primo luogo? Cosa significa? –

+0

Il framework genera eccezioni internamente. Finché non è emerso dal codice utente, non dovresti preoccuparti del perché sta accadendo. Visual Studio dovrebbe avere un'opzione di debug in cui si interrompe solo sull'eccezione generata dal codice utente. –

+8

Questo non è accettabile. Spreca una quantità di tempo fastidiosa ogni volta che VS deve interrompere l'esecuzione per visualizzare questa eccezione. Non essere così felice nel quadro. –

0

Ho risolto questo con l'aggiunta di

using System.Runtime.InteropServices.WindowsRuntime; 

Non rimuovere questa riga. Il "sort and remove usings" automatico (nel mio caso) lo rimuoverà, causando questo problema criptico. No, non so perché. Ma so che è la causa.

+0

Dove dovrei aggiungere questo? – seb

+0

IIRC, in cui si sta utilizzando l'attività o solo nella sezione principale (dove circola l'eccezione). – Andy

+0

Questo non sembra fare nulla. –

1

Il problema esiste ancora e l'eccezione stessa può essere ignorata come altre risposte. Ma se l'operazione asincrona è racchiusa da try/catch, l'eccezione verrebbe catturata e l'altra operazione nello stesso try/catch non verrebbe eseguita, questo è il problema.

Basta mettere questo prima dell'operazione asincrona sarebbe meglio questo.

try 
{ 
    await Task.Delay(1); 
} 
catch 
{ 
    // do nothing 
} 

eccezione si verifica ancora Task.Delay (1), ma dopo che sarebbe non verificarsi seguente operazione asincrona.

Problemi correlati