我使用WPF来编写我的界面。我用的ListView我的任务list.Task列表包含两列,文件名,Progress.every行绑定到TASKINFO:如何在c中使用ref属性#
public class TaskInfo : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public TaskInfo(string fp)
{
FileSystemInfo fsi= new DirectoryInfo(fp);
FileName = fsi.Name;
FilePath = fp;
PbValue = 0;
}
private int pbvalue;
public int PbValue
{
get { return pbvalue; }
set
{
pbvalue = value;
onPropertyChanged("PbValue");
}
}
private string filename;
public string FileName
{
get { return filename;}
set
{
filename = value;
onPropertyChanged("FileName");
}
}
private string filepath;
public string FilePath
{
get { return filepath;}
set
{
filepath = value;
onPropertyChanged("FilePath");
}
}
private void onPropertyChanged(string name)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
在进度列,它包含一个进度条,结合其值设置为PbValue。 但是由于某种原因,我应该使用C语言编写的Dll。 我用的功能是:
WaterErase(char * filepath, int * pbvalue)
我确定它在C#:
public extern static void WaterErase(string filepath, ref int pbvalue)
执行多任务,我写了一个主题:
class TaskThread
{
private TaskInfo taskinfo = null; //task information
private Thread thread;
public TaskThread(TaskInfo _taskinfo)
{
taskinfo = _taskinfo;
}
private void run()
{
WaterErase(taskinfo.FilePath, ref taskinfo.PbValue);
}
public void start()
{
if (thread == null)
{
thread = new Thread(run);
thread.Start();
}
}
}
但行:
WaterErase(taskinfo.FilePath, ref taskinfo.PbValue);
has probl EM:
的属性,索引器或动态成员访问不可能会作为传出或引用参数
我知道为什么这个问题出现了,但如何解决这个问题,以实现这一功能被传递即实时更改PbValue。所以我可以直观地在ProgressBar中执行任务进度
但是不会显示实时进度。当WaterErase函数完成时,ProgressBar的值将直接变为100 – cloudending