UIなしで実行されるFTPプロセスがあります。そして、このftpコントロールを使用するwinformがあります。そのウィンドウには、ftpアップロードの進行状況を示すプログレスバーがあります。進行状況は、基になるプレゼンターで更新される間期を介してウィンドウに到着します(私はMVPパターンを使用しています)。
私の問題は、進行状況を更新しようとすると、常にこの例外がスローされることです。
スレッドを介した不正な操作:コントロール'prgProgresoSubido'は、作成したスレッド以外のスレッドからアクセスされます。
フォームでBackGroundWorkerを使用しても、この問題は解決しません。
// This is a delegated on presenter when a File finish to upload
void client_FileUploadCompletedHandler(object sender, FileUploadCompletedEventArgs e)
{
string log = string.Format("{0} Upload from {1} to {2} is completed. Length: {3}. ",
DateTime.Now, e.LocalFile.FullName, e.ServerPath, e.LocalFile.Length);
archivosSubidos += 1;
_Publicacion.ProgresoSubida = (int)((archivosSubidos / archivosXSubir) * 100);
//this.lstLog.Items.Add(log);
//this.lstLog.SelectedIndex = this.lstLog.Items.Count - 1;
}
// This is My interfase
public interface IPublicacion
{
...
int ProgresoSubida { set; }
}
/// And Here is the implementartion of the interfase on the form
public partial class PublicarForm : Form ,IPublicacion
{
//Credenciales para conectarse al servicio FTP
public FTPClientManager client = null;
public XmlDocument conf = new XmlDocument();
public string workingDir = null;
public webTalk wt = new webTalk();
private readonly PublicacionesWebBL _Publicador;
public PublicarForm()
{
InitializeComponent();
String[] laPath = { System.AppDomain.CurrentDomain.BaseDirectory};
String lcPath = System.IO.Path.Combine(laPath);
_Publicador = new PublicacionesWebBL(this, lcPath);
}
public int ProgresoSubida
{
set
{
// This is my prograss bar, here it throw the exception.
prgProgresoSubido.Value = value;
}
}
}
この問題を回避するにはどうすればよいですか?