我用WPF编写我的界面.我使用ListView作为我的任务列表.任务列表包含两列,FileName,Progress.every绑定到TaskInfo的行:
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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
在"进度"列中,它包含ProgressBar,将其值绑定到PbValue.但是出于某些原因,我应该使用C语言编写的Dll.我使用的功能是:
WaterErase(char * filepath, int * pbvalue)
Run Code Online (Sandbox Code Playgroud)
我在c#中确定了它:
public extern static void WaterErase(string filepath, ref int pbvalue)
Run Code Online (Sandbox Code Playgroud)
执行多任务,我写了一个线程:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是这条线:
WaterErase(taskinfo.FilePath, ref taskinfo.PbValue);
Run Code Online (Sandbox Code Playgroud)
有问题:
属性,索引器或动态成员访问不能作为out或ref参数传递
我知道为什么会出现这个问题,但是如何解决这个问题来实现这个实时改变PbValue的功能.所以我可以直观地在ProgressBar中执行任务进度
正如错误所说,你不能这样做.但是您可以使用局部变量:
int temp = taskinfo.PbValue;
WaterErase(taskinfo.FilePath, ref temp);
taskinfo.PbValue = temp;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
860 次 |
| 最近记录: |