c# - 如何在 dll 中的另一个表单上重定向进程输出
问题描述
我要从 delphi 到 c#,我是一个新手 c#,我的代码运行良好:
//表格1
public void Scan(string fOut)
{
Form2 frm2;
void SortOutputHandler(object sender, DataReceivedEventArgs e)
{
Trace.WriteLine(e.Data);
this.BeginInvoke(new MethodInvoker(() =>
{
frm2.addItem(e.Data ?? string.Empty);
}));
}
using (Process p = new Process())
{
frm2 = new Form2();
frm2.Show(this);
p.StartInfo.RedirectStandardError = true;
// necessary code
p.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
p.Start();
p.BeginOutputReadLine();
while (!p.HasExited)
{
Application.DoEvents();
}
p.Close();
frm2.Close();
frm2.Dispose();
}
}
//表格2
public void addItem(string line)
{
listBox1.Items.Add(line);
}
private void Form2_Shown(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
我想将代码移动到 dll,但找不到调用 dllname.Scan("fn.xxx") 的 Form1 引用:
this.BeginInvoke..
提前致谢
解决方案
推荐阅读
- reactjs - React:切换渲染组件
- javascript - 如何检查用户是否已经拥有该属性?
- php - 仅当 jsonObj 有值时才显示图像
- monitoring - Prometheus:不是有效的主机名
- microsoft-graph-api - 类端点不返回所有用户的类
- python - 将 Dataframe 行转换为列 Pandas Python
- safari - 如何在 Safari 中请求替代视频输入?
- memory - 如何以内存高效格式将哈希图写入文件?
- apache - 如何修改包含路径和参数的查询字符串?
- javascript - 在 HTML 中选择标签上的搜索过滤器逻辑