の処理時間がかかるpythonスクリプトの実行中に、バックグラウンドワーカーでIUを管理してプログレスバーを表示します。バックグラウンドワーカーエラー
イベント「OutputDataReceived
」が必要ないときにバックグラウンドワーカーを正常に使用しましたが、私が使用しているスクリプトでは( "10"、 "80"、..)のような進捗値が表示されますイベントOutputDataReceived
を聞いてください。
このエラーは、This operation has already had OperationCompleted called on it and further calls are illegal.
この行に表示されますprogress.bw.ReportProgress(v);
です。
2つのバックグラウンドワーカーインスタンスを使用しようとしましたが、1つは実行され、もう1つはリッスンしますが、エラーは発生しませんが、イベント 'OutputDataReceived'を呼び出さないようです。
private void execute_script()
{
progress.bw.DoWork += new DoWorkEventHandler(//progress.bw is reference to the background worker instance
delegate(object o, DoWorkEventArgs args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "python.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments = @".\scripts\script1.py " + file_path + " " + txtscale.Text;
//proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;
//proc.EnableRaisingEvents = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardError = true;
proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
proc.Start();
proc.BeginOutputReadLine();
//proc.WaitForExit();
//proc.Close();
});
progress.bw.RunWorkerAsync();
}
///the function called in the event OutputDataReceived
void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
//throw new NotImplementedException();
if (e.Data != null)
{
int v = Convert.ToInt32(e.Data.ToString());
MessageBox.Show(v.ToString());
// report(v);
progress.bw.ReportProgress(v);
}
else
MessageBox.Show("null received");
}
C#4はPythonを少し直接サポートしていることは知っていますか? –
Iron Pythonへの私の関わりは、ArcpyをIron pythonにバインドするのはかなり簡単ではないので、 "Arcpy"を使用しています。 – geogeek