BackgroundWorker

来源:互联网 发布:电脑群发短信软件 编辑:程序博客网 时间:2024/06/10 18:48

BackgroundWorker的事件响应函数:

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)        {            BackgroundWorker worker = sender as BackgroundWorker;            demoProcess = new Process();            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);            ProcessStartInfo info = new ProcessStartInfo(Assembly.GetEntryAssembly().GetName().Name + ".exe");            info.Arguments = string.Join(" ", (string[])e.Argument);            info.RedirectStandardOutput = true;            info.UseShellExecute = false;            info.CreateNoWindow = true;            demoProcess.StartInfo = info;            demoProcess.Start();            while (demoProcess != null && !demoProcess.StandardOutput.EndOfStream)            {                if (worker.CancellationPending == true)                {                    e.Cancel = true;                    break;                }                string message = demoProcess.StandardOutput.ReadLine();                if (this.InvokeRequired)                    this.Invoke(new AddItemHander(AddItem), message);                else                    AddItem(message);            }            //at this stage application has finished and we can leave this worker...            //but let's do cleaning work anyway            if (!IsStoppingAnalysisByUser)            {                CleanDemoProcess(String.Empty);            }            else            {                IsStoppingAnalysisByUser = false;            }        }

 

 

 

原创粉丝点击