熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> ASP編程 >> 正文

c#中重定向windows控制台程序的輸出信息

2022-06-13   來源: ASP編程 

  這個問題來自社區提問代碼保留一份用來以後回答

  

  

  using System;
using SystemComponentModel;
using SystemWindowsForms;
namespace WindowsApplication
{
/**////


/// gui 類
///

public partial class Form : Form
{
public Form()
{
InitializeComponent();
}
private void button_Click(object sender EventArgs e)
{
//用子線程工作
new SystemThreadingThread(new SystemThreadingThreadStart(StartDownload))

  Start();
}
//開始下載
public void StartDownload()
{
Downloader downloader = new Downloader();
downloaderonDownLoadProgress += new DownloaderdDownloadProgress(downloader_

  onDownLoadProgress);
downloaderStart();
}
//同步更新ui
void downloader_onDownLoadProgress(long total long current)
{
if (thisInvokeRequired)
{
thisInvoke(new DownloaderdDownloadProgress(downloader_onDownLoadProgress)

  new object[] { total current });
}
else
{
thisprogressBarMaximum = (int)total;
thisprogressBarValue = (int)current;
}
}
}

  /**////


/// 下載類
///

public class Downloader
{
//委托
public delegate void dDownloadProgress(long totallong current);
//事件
public event dDownloadProgress onDownLoadProgress;
//開始模擬工作
public void Start()
{
for (int i = ; i < ; i++)
{
if (onDownLoadProgress != null)
onDownLoadProgress( i);
SystemThreadingThreadSleep();
}
}
}
}


From:http://tw.wingwit.com/Article/program/ASP/201311/21779.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.