创建一个zip文件时,我试图向状态栏报告进度。
为了报告创建进度,我使用了以下指南:
ZipFile Creation Report Progress
我的状态栏当前使用2个类进行更新:
INotifyPropertyChanged
的{{1}}类StatusBar
的单独类。 Status
类:
StatusBar
public class StatusBar : INotifyPropertyChanged
{
private string _message;
private string _submessage;
private bool _isindeterminate;
private bool _visible;
private int _min;
private int _max;
private double _progress;
public event PropertyChangedEventHandler PropertyChanged;
public StatusBar() { }
public int Min
{
get { return this._min; }
set
{
this._min = value;
this.OnPropertyChanged("Min");
}
}
public int Max
{
get { return this._max; }
set
{
this._max = value;
this.OnPropertyChanged("Max");
}
}
public double Progress
{
get { return this._progress; }
set
{
this._progress = value;
this.OnPropertyChanged("Progress");
}
}
public string Message
{
get { return this._message; }
set
{
this._message = value;
this.OnPropertyChanged("Message");
}
}
public string SubMessage
{
get { return this._submessage; }
set
{
this._submessage = value;
this.OnPropertyChanged("SubMessage");
}
}
public bool IsIndeterminate
{
get { return this._isindeterminate; }
set
{
this._isindeterminate = value;
this.OnPropertyChanged("IsIndeterminate");
}
}
public bool Visible
{
get { return this._visible; }
set
{
this._visible = value;
this.OnPropertyChanged("Visible");
}
}
void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
类:
Status
为了创建zip文件和更新状态栏,我目前具有以下内容:
public class Status
{
public static void Initialise(StatusBar status, string _message, string _submessage, int _min, int _max, double _progress, bool _visible, bool _isindeterminate)
{
status.Visible = _visible;
if (_isindeterminate == false)
{
status.Message = _message;
status.SubMessage = _submessage;
status.Progress = _progress;
status.Min = _min;
status.Max = _max;
status.IsIndeterminate = _isindeterminate;
}
else
{
status.Message = _message;
status.IsIndeterminate = _isindeterminate;
}
}
public static void UpdateProgress(StatusBar status, double _progress)
{
if (_progress == status.Max)
{
Complete(status);
}
else
{
status.Progress = _progress;
}
}
public static void UpdateMessage(StatusBar status, string _message)
{
status.Message = _message;
}
public static void UpdateSubMessage(StatusBar status, string _submessage)
{
status.SubMessage = _submessage;
}
public static void UpdateProgressMessage(StatusBar status, string _message, double _progress)
{
status.Message = _message;
status.Progress = _progress;
}
public static void Complete(StatusBar status)
{
status.Message = "Ready";
status.SubMessage = " ";
status.Min = 0;
status.Max = 0;
status.Progress = 0;
status.Visible = false;
status.IsIndeterminate = false;
}
}
上面的代码正在工作,并且Zip文件已创建。
但是,仅在过程完成后才报告进度,而在过程中则不会报告。
在创建zip文件期间,如何更改此设置以更新进度?