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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:53+00:00 2026-06-13T02:21:53+00:00

in my application i am open Tshark process and start capturing and from my

  • 0

in my application i am open Tshark process and start capturing and from my main form i am update my UI.
one of my class properties is my file how created (pcap file) and on my UI i am update this file length ongoing.
my problem is that if this file is new the length is remain zero but if my file is file that already exist my UI show my the length ongoing (of course the file is overwritten but i can see it growing).

    public class Tshark
    {
        #region members
        private Process _tsharkProcess = new Process();
        private int _numberOfPackets;
        private string _tshark;
        private List<string> _list;
        private ProcessStartInfo _process;
        private int _interfaceNumber;
        private string _pcapPath;
        private string _status;
        private double _bitsPerSecond;
        private double _packetsPerSecond;
        private decimal _packetLimitSize;
        private DateTime _lastTimestamp;
        private PacketDevice _device;
        private FileInfo _file;
        private bool _processRunning;

        public void startCapturing()
        {            
            ThreadStart tStarter = delegate { openAdapterForStatistics(_device); };
            Thread thread = new Thread(tStarter);
            thread.IsBackground = true;
            thread.Start();
            ProcessStartInfo tsharkStartInfo = new ProcessStartInfo();
            tsharkStartInfo.FileName = _tshark; 
            tsharkStartInfo.RedirectStandardOutput = true; 
            tsharkStartInfo.RedirectStandardError = true; 
            tsharkStartInfo.RedirectStandardInput = true; 
            tsharkStartInfo.UseShellExecute = false; 
            tsharkStartInfo.CreateNoWindow = true; 
            tsharkStartInfo.Arguments = string.Format(" -i " + _interfaceNumber + " -s " + _packetLimitSize + " -w " + _pcapPath);
            _tsharkProcess.StartInfo = tsharkStartInfo;
            _tsharkProcess.ErrorDataReceived += _cmdProcess_ErrorDataReceived;
            _tsharkProcess.OutputDataReceived += tshark_OutputDataReceived; 
            _tsharkProcess.EnableRaisingEvents = true; 
            _tsharkProcess.Start();
            _processRunning = true;
            _tsharkProcess.BeginOutputReadLine(); 
            _tsharkProcess.BeginErrorReadLine();
_tsharkProcess.WaitForExit(); 
        }

    public long getFileLength()
    {
        _file = new FileInfo(_pcapPath);
        string directoryName = _file.DirectoryName;
        DirectoryInfo directoryInfo = new DirectoryInfo(directoryName);
        FileInfo[] dirs = directoryInfo.GetFiles();
        _file = dirs.FirstOrDefault(f => f.Name.Equals(_file.Name));

        if (_file != null)
        {

            return _file.Length;
        }

        return 0;
    }

        public void refreshFile()
        {            
            if (_file != null)
            {
                _file.Refresh();
            }
        }
}

from the main form i am update my UI via timer:

private void tmrUpdateLbl_Tick(object sender, EventArgs e)
{
    lblFileSizeTabSniffer2.Text = formatBytes(tshark.getFileLength());
    tshark.refreshFile();
}

in the dibugger i can see that if the file is new one _file is null all the time so in getFileLength() method return zero.

  • 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-13T02:21:55+00:00Added an answer on June 13, 2026 at 2:21 am

    You need to get the full FileInfo every time (i.e. in getFileLength) to get up-to-date results. Move relevant code from startCapturing to getFileLength.

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

Sidebar

Related Questions

i have application how open Tshark process and start capturing packet, this process create
in my application i m open Wireshark process and start capturing packts, in the
How do I make my java application open one of those fancy file selection
I need from my C# application open a PDF file by using Foxit Reader
I have built an open-source application from the source code. Unfortunately, the original executable
My application is trying to open a text file, and is presented with a
I have an application wich open a modal form with the ShowDialog method. Once
I am writing a simple Word Interop application which open a .doc file in
I'm new to Open Xml, and have created a reporting application using Open Xml
How can I make a Win32 application open a file at startup when calling

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.