Ho Windows sotto forma di app questo è il mio codice:Progress <T> non ha funzione di report
private async void btnGo_Click(object sender, EventArgs e)
{
Progress<string> labelVal = new Progress<string>(a => labelValue.Text = a);
Progress<int> progressPercentage = new Progress<int>(b => progressBar1.Value = b);
// MakeActionAsync(labelVal, progressPercentage);
await Task.Factory.StartNew(()=>MakeActionAsync(labelVal,progressPercentage));
MessageBox.Show("Action completed");
}
private void MakeActionAsync(Progress<string> labelVal, Progress<int> progressPercentage)
{
int numberOfIterations=1000;
for(int i=0;i<numberOfIterations;i++)
{
Thread.Sleep(10);
labelVal.Report(i.ToString());
progressPercentage.Report(i*100/numberOfIterations+1);
}
}
ottengo errore di compilazione che "System.Progress' non contiene una definizione per 'Report' e senza estensione metodo 'report' accettare un primo argomento di tipo 'System.Progress' stato trovato (che le manca un un riferimento all'assembly direttiva using o?)"
ma Se si guarda alla classe Progress:
public class Progress<T> : IProgress<T>
e l'interfaccia IProgress ha la funzione Report:
public interface IProgress<in T>
{
// Summary:
// Reports a progress update.
//
// Parameters:
// value:
// The value of the updated progress.
void Report(T value);
}
Che cosa mi manca?
cosa si intende per "implementazione dell'interfaccia esplicita" il metodo di interfaccia non dovrebbe essere visibile in sottoclasse? –
@ilayzeidman L'ho spiegato [qui] (http://stackoverflow.com/a/25585242/2530848) –
Grazie! Capisco che non sapevo di questa opzione ... –