2015-05-01 3 views
22

Ricevo improvvisamente uno strano errore durante il debug. Fino ad ora la variabile nelle finestre di controllo è stata mostrata correttamente. Ora ricevo sempre il messaggio di errore in Watch Windows: "La valutazione della funzione richiede l'esecuzione di tutti i thread". Non sono più in grado di controllare alcuna variabile. Non lavoro esplicitamente con Threads. Cosa posso fare per farlo funzionare di nuovo. Ho disabilitato, come menzionato in alcuni forum, la funzione: "Abilita la valutazione delle proprietà e altre chiamate di funzioni implicite" nella finestra delle opzioni del debugger. Ma senza successo, allora sto ricevendo l'errore: "Errore nella valutazione della funzione implicita disabilitata dall'utente".Visual Studio durante il debug: la valutazione della funzione richiede l'esecuzione di tutti i thread

Qualcuno può aiutarmi e farlo risolvere. Grazie.

Cheers, Maik

+0

Per ottenere il punto dell'elenco: Hai riavviato Visual Studio? – MUG4N

+0

Sì, l'ho fatto. Riavviato e stesso problema. – Maik

+0

verificarlo: http://stackoverflow.com/questions/4280604/evaluation-requires-a-thread-to-run-temporarily-use-the-watch-window-to-perform – MUG4N

risposta

34

dal forum msdn:

This isn't an error in and of itself, but more of a feature of your debugger. Some properties require code to be executed in order for the property to be read, but if this requires cross-thread interaction, then other threads may have to run as well. The debugger doesn't do this automatically, but certainly can, with your permission. Just click the little evaluate icon and it will run your code and evaluate the property.

enter image description here

Per ulteriori dettagli su questo comportamento controllare questo eccellente article

+3

Ho letto questo articolo. Non ho un pulsante del genere per fare clic, quindi non esattamente il problema che ho. È abbastanza strano che funzionasse da quando ho aggiornato a Visual Studio 2015 RC oggi. – Maik

+0

Anche quel piccolo taglio non funziona più, quando si cerca di ottenere il valore del risultato con l'aiuto della finestra di controllo. public IEnumerable MappingQuery() { var context = new DatabaseEntities(); context.Database.Connection.ConnectionString = GlobalData.ConnectionString; var = Risultati da una in context.Mapping selezionare Nuovo clsDefinitions.Mapping { valore1 = a.value1, value2 = a.value2 }; resi; – Maik

+0

Lo stesso problema qui: http://stackoverflow.com/questions/4460206/lazyt-the-function-evaluation-requires-all-threads-to-run – MUG4N

0

ho utilizzare la soluzione successiva per passare :

var OtherThreadField = ""; 
Invoke(new MethodInvoker(delegate 
        { 
         OtherThreadField = ExecuteNeededMEthod(); 
        })); 

Ora ho un valore per OtherThreadField.

1

È necessario effettuare chiamate thread-safe perché l'accesso ai controlli di modulo di Windows non è thread sicuro nel multithreading. Questo è il mio semplice codice che rende Thread sicuro chiamata e imposta la barra di avanzamento.

public partial class Form1 : Form 
{// This delegate enables asynchronous calls for setting 
    // the text property on a TextBox control. 
    delegate void StringArgReturningVoidDelegate(string text); 
    private Thread demoThread = null; 

    public int Progresscount = 0; 
    static EventWaitHandle waithandler = new AutoResetEvent(false); 
    public Form1() 
    { 
     InitializeComponent(); 
    } 
    public static bool CheckForInternetConnection() 
    { 
     try 
     { 


      using (var client = new WebClient()) 
      { 
       using (var stream = client.OpenRead("http://www.google.com")) 
       { 
        return true; 
       } 
      } 
     } 
     catch 
     { 
      return false; 
     } 
    } 

    public void Progressincrement() 
    { 

     waithandler.WaitOne(); 
     while (CheckForInternetConnection()==true) 
     { 
      if (Progresscount==100) 

      { 
       break; 
      } 
      SetLabel("Connected"); 
      Progresscount += 1; 

     SetProgress(Progresscount.ToString()); 
      Thread.Sleep(TimeSpan.FromSeconds(1)); 
     } 
     if (Progresscount <100) 
     { 
      Startthread(); 
     } 
     SetLabel("Completed"); 


    } 

    public void Startthread() 
     { 

    this.demoThread= new Thread(new ThreadStart(Progressincrement)); 
     this.demoThread.Start(); 
    SetLabel("Waiting for connection"); 
     while (CheckForInternetConnection() == false) ; 

     waithandler.Set(); 
    } 
    private void SetLabel(string text) 
    { 
     // InvokeRequired required compares the thread ID of the 
     // calling thread to the thread ID of the creating thread. 
     // If these threads are different, it returns true. 
     if (this.label1.InvokeRequired) 
     { 
      StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(SetLabel); 
      this.Invoke(d, new object[] { text }); 
     } 
     else 
     { 
      this.label1.Text = text; 
     } 
    } 
    private void SetProgress(string Value) 
    { 
     // InvokeRequired required compares the thread ID of the 
     // calling thread to the thread ID of the creating thread. 
     // If these threads are different, it returns true. 
     if (this.progressBar1.InvokeRequired) 
     { 
      StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(SetProgress); 
      this.Invoke(d, new object[] {Value}); 
     } 
     else 
     { 
      this.progressBar1.Value = Convert.ToInt32(Value); 
     } 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     Startthread(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     MessageBox.Show("Responsive"); 
    } 
} 

Per ulteriori informazioni MSDN

0

MUG4N ha infatti fornito una risposta corretta se si passa sopra la riga di codice in di debug, si può guardare qualcosa di simile alla seguente. In tal caso, fare clic sul piccolo rivalutare icona evidenziata nell'immagine sotto ...

enter image description here

NB: Ho ottenuto questa immagine da appuntare, normalmente la rivalutare icone sono nel mezzo del finestra e non giù nella colonna di sinistra.