Ich habe Windows Form app dies ist mein Code:Fortschritt <T> nicht über Reportfunktion
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);
}
}
ich Kompilierungsfehler, dass „System.Progress' keine Definition enthält für‚Report‘und keine Erweiterung Methode ‚Report‘ ein erstes Argument vom Typ ‚System.Progress‘ Annahme gefunden werden (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis?)“
aber Wenn Sie Fortschritt Klasse aussehen:
und die Schnittstelle IProgress hat Funktion Report:
public interface IProgress<in T>
{
// Summary:
// Reports a progress update.
//
// Parameters:
// value:
// The value of the updated progress.
void Report(T value);
}
Was bin ich?
was Sie mit „expliziter Schnittstellenimplementierung“ bedeuten die Interface-Methode sollte nicht in der Unterklasse sichtbar sein? –
@ilayzeidman Ich erklärte es [hier] (http://stackoverflow.com/a/25585242/2530848) –
Vielen Dank! Ich verstehe, dass ich über solche Option nicht gewusst habe ... –