对于你的问题,参看我的例子就可以了,我的例子是如何滚动进度条,那么你可以在上面的基础上进行扩展,而且Invoke调用方法,也可以加参数,例如:
-------in your form class ------
public void ShowText( string sData )
{
//Handle "sData" here
}
--------in thread fun ----------
MethodInvoker mi = new MethodInvoker( this.ShowText );
this.BeginInvoke( mi, new object[]{ yourText } );
I have a question as the following:
foreach(int i in ...)
{
//the order is important, that is:
//DoSomthing(2) must be done after the DoSomething(1) is completed
DoSomething(i);
}
private void DoSomething(int i)
{
//In here, a function to upload file will be called,
//and it will be implemeted by using class Upload, who is inherited from BackgroundWorker and will call a WSE
// to upload the file, so the speed is a bit slow
}
So my question is how to make the DoSomthing(2) only begins when the DoSomthing(1) is finished.
I have tried the Invoke, but the ui seem to be dead, and the import order seems to wrong.
For example:
PackageA: no files to import
PackageB: need to import files
PackageC: no files to import
After the PackageA is finished, and the PackageB will start and begin import file, but even the PackageB has not been finished, the PackageC will start.
private delegate bool ImportSinglePackage();
private ImportSinglePackage importSinglePackage = null;
//The UI will call the BeginImport to start the importing
public BeginImport()
{
Cursor.Current = Cursors.WaitCursor;
this.importSinglePackage = new ImportSinglePackage(this.ImportBySinglePackage);
mImportingDataThread = new Thread(new ThreadStart(this.ImportPackages));
mImportingDataThread.Start();
}