BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / dot-net / #4618同步于 2015/3/20
dotNET机器人发帖

[问题]c# 只能出现在+=或-=的左边

jack314
2015/3/20镜像同步0 回复
C#小白,C#界面程序出现了以下问题事件 只能出现在+=或-=的左边 网上也查了,改了下,但是不成功。请问出错的红色部分该如何修改? 谢谢 using System; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Windows.Forms; namespace iPerfGui { public class iperf { public delegate void OnOutputChanged(string output); public delegate void OnProcessStatusChanged(); private readonly BackgroundWorker bw; private Process process; public event iperf.OnProcessStatusChanged ProcessStoped { [MethodImpl(MethodImplOptions.Synchronized)] add { ProcessStoped += value; } [MethodImpl(MethodImplOptions.Synchronized)] remove { ProcessStoped -= value; } } public event iperf.OnProcessStatusChanged ProcessStarted { [MethodImpl(MethodImplOptions.Synchronized)] add { ProcessStarted += value; } [MethodImpl(MethodImplOptions.Synchronized)] remove { ProcessStarted -= value; } } public event iperf.OnOutputChanged OutputChanged { [MethodImpl(MethodImplOptions.Synchronized)] add { OutputChanged += value; } [MethodImpl(MethodImplOptions.Synchronized)] remove { OutputChanged -= value; } } public iperf() { this.bw = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; } private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.bw.ProgressChanged -= new ProgressChangedEventHandler(this.bw_ProgressChanged); this.bw.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted); this.bw.DoWork -= new DoWorkEventHandler(this.bw_DoWork); this.bw.Dispose(); if (this.ProcessStoped != null) { this.ProcessStoped(); } } private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.UserState != null) { this.OutputChanged((string)e.UserState); } } public void Start(string arg) { if (!File.Exists(Application.StartupPath + "\\iperf.exe")) { MessageBox.Show("iperf.exe not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } if (this.bw != null && !this.bw.IsBusy) { this.bw.DoWork += new DoWorkEventHandler(this.bw_DoWork); this.bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted); this.bw.ProgressChanged += new ProgressChangedEventHandler(this.bw_ProgressChanged); this.bw.RunWorkerAsync(arg); if (this.ProcessStarted != null) { this.ProcessStarted(); } } } public void Stop() { if (this.process == null) { return; } if (this.process.HasExited) { return; } this.process.Kill(); } private void bw_DoWork(object sender, DoWorkEventArgs e) { try { this.process = new Process { EnableRaisingEvents = true, StartInfo = { FileName = Application.StartupPath + "\\iperf.exe", Arguments = (string)e.Argument, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, RedirectStandardOutput = true } }; this.process.OutputDataReceived += new DataReceivedEventHandler(this.process_OutputDataReceived); this.process.Exited += new EventHandler(this.process_Exited); this.process.Start(); this.process.BeginOutputReadLine(); this.process.WaitForExit(); } catch (Exception ex) { this.Stop(); MessageBox.Show(ex.Message, "Process start failed", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } private void process_Exited(object sender, EventArgs e) { this.process.OutputDataReceived -= new DataReceivedEventHandler(this.process_OutputDataReceived); this.process.Exited -= new EventHandler(this.process_Exited); } private void process_OutputDataReceived(object sender, DataReceivedEventArgs e) { this.bw.ReportProgress(0, e.Data); } } }
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。