I have a program that has classes
- GUI
- Download
- and a buffer between two classes - i.e. used for communication between two classes.
The class is Uploadused Processto run an FTP command line application. I want to return what result created by the FTP application will be displayed in textboxthe GUI.
I tried using the following code, which was truncated.
Load class (beginProcess () is the method used to start Thread (not shown here)):
public delegate void WputOutputHandler(object sender, DataReceivedEventArgs e);
class Upload
{
private WputOutputHandler wputOutput;
beginProcess()
{
Process pr = new Process();
pr.StartInfo.FileName = @"wput.exe";
pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pr.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
pr.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived);
pr.Start();
pr.BeginOutputReadLine();
pr.WaitForExit();
}
public void OnDataReceived(object sender, DataReceivedEventArgs e)
{
if(wputOutput != null)
{
wputOutput(sender, e);
}
}
public event WputOutputHandler WputOutput
{
add
{
wputOutput += value;
}
remove
{
wputOutput -= value;
}
}
}
Buffer class:
public void EventSubscriber()
{
uploadSession.WputOutput += Main.writeToTextBoxEvent;
}
Main class:
public void writeToTextBoxEvent(object sender, DataReceivedEventArgs e)
{
if(this.textBox1.InvokeRequired)
{
MethodInvoker what now?
}
else
{
textBox1.Text = e.Data;
}
}
, Main writeToTextBoxEvent, . , - . - , .