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 8600503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:37:54+00:00 2026-06-12T01:37:54+00:00

I want my application will show on my form my class properties so I

  • 0

I want my application will show on my form my class properties so I started my class with BackgroundWorker and create ProgressChanged.

my class:

public class DumpFile
{
    PacketDevice _device;
    public int _packetsCount;
    public double _bitsPerSecond;
    public double _packetsPerSecond;
    public DateTime _lastTimestamp;
    public delegate void dlgPackProgress(int progress);
    public event dlgPackProgress evePacketProgress;

    public DumpFile(PacketDevice device, string pcapPath)
    {
        _device = device;
        _pcapPath = pcapPath;
        _packetsCount = 1;
    }

    public void startCapturing()
    {
OnPacketProgress(_packetsCount++);

        using (PacketCommunicator communicator = _device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) //open the device
        {
            ThreadStart starter = delegate { openAdapterForStatistics(_device); };
            new Thread(starter).Start();

            using (PacketDumpFile dumpFile = communicator.OpenDump(_pcapPath)) //open the dump file
            {
                communicator.ReceivePackets(0, dumpFile.Dump); //start the capture                    
            }
        }
    }
private void OnPacketProgress(int packet)
{
    var handler = evePacketProgress;
    if (handler != null)
    {
        handler(packet);
    }
}

    public void openAdapterForStatistics(PacketDevice selectedOutputDevice)
    {
        using (PacketCommunicator statCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000)) //open the output adapter
        {
            ThreadStart start = delegate { test(selectedOutputDevice); };
            new Thread(start).Start();

            statCommunicator.SetFilter("tcp"); //compile and set the filter
            statCommunicator.Mode = PacketCommunicatorMode.Statistics; //put the interface in statstics mode                
            statCommunicator.ReceiveStatistics(0, StatisticsHandler);

        }
    }

    public void test(PacketDevice selectedOutputDevice)
    {
        using (PacketCommunicator communicator = selectedOutputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
        {
            communicator.ReceivePackets(0, PacketHandler);
        }
    }

    private void PacketHandler(Packet packet)
    {
        string result = _packetsCount.ToString() + ". " + packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " length:" + packet.Length;
        _packetsCount++;
    }

    private void StatisticsHandler(PacketSampleStatistics statistics)
    {
        DateTime currentTimestamp = statistics.Timestamp; //current sample time
        DateTime previousTimestamp = _lastTimestamp; //previous sample time
        _lastTimestamp = currentTimestamp; //set _lastTimestamp for the next iteration

        if (previousTimestamp == DateTime.MinValue) //if there wasn't a previous sample than skip this iteration (it's the first iteration)
        {
            return;
        }

        double delayInSeconds = (currentTimestamp - previousTimestamp).TotalSeconds; //calculate the delay from the last sample
        _bitsPerSecond = statistics.AcceptedBytes * 8 / delayInSeconds; //calculate bits per second
        _packetsPerSecond = statistics.AcceptedPackets / delayInSeconds; //calculate packets per second
    }
}

start button who start capturing:

private void btnStartCapture_Click(object sender, EventArgs e)
{
    timerSniffer.Start();
    btnStartTabSniffer.Enabled = false;
    btnStopTabSniffer.Enabled = true;
    groupBoxSelectTabSniffer.Enabled = false;

    bgWorker = new BackgroundWorker();
    bgWorker.WorkerReportsProgress = true;
    bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWSniffer_ProgressChanged);
    bgWorker.DoWork += new DoWorkEventHandler(
        (s3, e3) =>
        {
            DumpFile dumpFile = new DumpFile(deviceForCapturing, pcapFilePathSniffer);

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

            dumpFile.startCapturing();
        });

    bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
        (s3, e3) =>
        {
            groupBoxSelectTabSniffer.Enabled = true;
        });

    bgWorker.RunWorkerAsync();
}

ProgressChanged:

private void bgWSniffer_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    var dumpFile = (DumpFile)e.UserState;
    lblNumberOfPacketsTabSniffer2.Text = dumpFile._packetsCount.ToString("#,##0");
    lblTrafficRateTabSniffer2.Text = (dumpFile._bitsPerSecond * 0.000001).ToString("0.##") + " Mbit/sec" + " (" + dumpFile._bitsPerSecond.ToString("#,##0") + " Bits/sec" + ")";
    lblPacketsRateTabSniffer2.Text = dumpFile._packetsPerSecond.ToString("#,##0") + " Packets/sec";
}

the problem is that my application “get into” ProgressChanged functions but only in one time.

I think I missed something in my class.

  • 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-12T01:37:55+00:00Added an answer on June 12, 2026 at 1:37 am

    I can only find one call to OnPacketProgress(), and it’s outside of any loop.

    public void startCapturing()
    {
       OnPacketProgress(_packetsCount++);
       ....
    }
    

    So Yes, that will only be called once.
    You need something inside ReceivePackets()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# Windows application that I want to ensure will show up
I want to build a simple application with the MVVM pattern. This application will
_Hey, I have a question. I want to write application which will have multiple
I want to implement an application which will work as a parser. User will
I want to write an application that will automatically detect and fill the text
I want to start an application which will use ajax push, however the web
I want to develop an application that will use mathematical programming to solve lp
I want to build an android application which will recognize my voice, convert it
I want my application to have a zoomable element which will allow the XAML
I want to build a Facebook application that will be available only to those

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.