Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:29:40+00:00 2026-06-12T05:29:40+00:00

I start a Process and want to get the process output in order to

  • 0

I start a Process and want to get the process output in order to show it on my form (winform), so I created ProgressChanged event. My problem is that from some reason I cannot get in to my progressChanged function.

My code:

BackgroundWorker bgWorker = null;
string pcapFilePathSniffer = "";

This is my class that starts the process:

public class Tshark
{
    public int _interfaceNumber;
    public string _pcapPath;
    Process _tsharkProcess;
    public int _packetsCount;
    public string _packet;        
    public string _tsharkPath = @"C:\Program Files\Wireshark\tshark.exe";
    public delegate void dlgPackProgress(int progress);
    public event dlgPackProgress evePacketProgress;

    public Tshark(int interfaceNumber, string pcapPath)
    {
        _interfaceNumber = interfaceNumber;
        _pcapPath = pcapPath;
    }

    public void startTheCapture()
    {
        try
        {
            List<string> list = new List<string>();
            _tsharkProcess = new Process();
            _tsharkProcess.StartInfo.FileName = @"C:\Program Files\Wireshark\tshark.exe";
            //_tsharkProcess.StartInfo.Arguments = string.Format(" -i " + _interfaceNumber + " -c " + int.MaxValue + " -w " + _pcapPath);
            _tsharkProcess.StartInfo.Arguments = string.Format("-i " + 2);
            _tsharkProcess.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
            _tsharkProcess.StartInfo.RedirectStandardOutput = true;
            _tsharkProcess.StartInfo.UseShellExecute = false;
            _tsharkProcess.StartInfo.CreateNoWindow = true;
            _tsharkProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            _tsharkProcess.Start();
            StreamReader myStreamReader = _tsharkProcess.StandardOutput;                

            while (!myStreamReader.EndOfStream)
            {
                evePacketProgress(_packetsCount);
                _packet = myStreamReader.ReadLine();
                list.Add(_packet);
                _packetsCount++;

                private void OnPacketProgress(int packet)
                {
                  var handler = evePacketProgress;
                  if (handler != null)
                  {
                     handler(packet);
                  }
                }
            }         

            _tsharkProcess.WaitForExit();                

        }
        catch (Exception e)
        {

        }
    }
}

start button who start to process:

private void btnStartCapture_Click(object sender, EventArgs e)
{
    bgWorker = new BackgroundWorker();
    bgWorker.WorkerReportsProgress = true;
    bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWSniffer_ProgressChanged);
    bgWorker.DoWork += new DoWorkEventHandler(
        (s3, e3) =>
        {
            tshark = new Tshark(2, pcapFilePathSniffer);
            tshark.startTheCapture();

            tshark.evePacketProgress += new Tshark.dlgPackProgress(
                (packet) =>
                {
                    bgWorker.ReportProgress(packet, tshark);
                });
        });

    bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
        (s3, e3) =>
        {

        });

    bgWorker.RunWorkerAsync();
}

ProgressChanged function:

private void bgWSniffer_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    tshark = e.UserState as Tshark;
    listBoxPacketsSnifferTab.Text += tshark._packet;
    lblPacketsReceived2.Text = tshark._packetsCount.ToString("#,##0");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:29:41+00:00Added an answer on June 12, 2026 at 5:29 am

    You should raise Tshark.evePacketProgress event from startTheCapture to call BackgroudWorker.ReportProgress. Something like this:

    private void OnPacketProgress(int packet)
    {
      var handler = evePacketProgress;
      if (handler != null)
      {
         handler(packet);
      }
    }
    
    public void startTheCapture()
    {
            // your code here
    
            while (!myStreamReader.EndOfStream)
            {
                _packet = myStreamReader.ReadLine();
                list.Add(_packet);
                OnPacketProgress(_packetsCount++);
            }
    
            // your code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to (need to) start a sub-process from a perl script that checks
I want to start a subprocess and watch it's redirected output. That not a
I want to start a Java program from PowerShell and get the results printed
I want to be able to start a process and then be able to
i want to call the command prompt command using Process.Start and then using StandardOutput
I want to start a background process in a Java EE (OC4J 10) environment.
I want to start automating more of my web development process so I'm looking
I'm trying to start the del command using System.Diagnostic.Process. Basically I want to delete
Often I want to get a nice readout what process are running and their
I have a process and want to start it again when it is killed.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.