Note that there are some explanatory texts on larger screens.

plurals
  1. POTimer didn't started in the second iteration although it never stop
    primarykey
    data
    text
    <p>I have annoying bug that i cannot find and will glad for some help.</p> <p>I have application who take <code>Wireshark</code> file (Pcap file) and play the packets using <code>Pcap.Net project</code> i just add my file into my <code>Listbox</code> and click <code>play button</code> the class that actually play the packet call <code>WiresharkFile</code> and i buid my application this way:</p> <p>After add all my files into my <code>Listbox</code> and click play another class called <code>Job</code> received in the constructor List of all my files and this class responsible to call <code>WiresharkFile</code> and play the files.</p> <p>this is my <code>Job</code> Class:</p> <pre><code>using packetPlayer; using PcapDotNet.Core; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace PacketPlayer.classes { public class Job { private decimal _loopCount; private int _currentFileNum; private bool _shouldContinue; public bool shouldContinue { get { return _shouldContinue; } set { _shouldContinue = value; if (!_shouldContinue) { foreach (WiresharkFile wf in wiresharkFileList) { wf.setIsStop(false); wf.setStopButton(false); } } } } private IEnumerable&lt;string&gt; _source; private PacketDevice _selectedOutputDevice; private double _speed; private int _parallelThreads; private decimal _loops; public CancellationTokenSource _tokenSource { get; set; } public delegate void StatusChangedDelegate(WiresharkFile wiresharkFile); public event StatusChangedDelegate statusChangedEvent; public Job(IEnumerable&lt;string&gt; source, PacketDevice selectedOutputDevice, double speed, int parallelThreads, decimal loops) { _source = source; _selectedOutputDevice = selectedOutputDevice; _speed = speed; _parallelThreads = parallelThreads; _loops = loops; _loopCount = 0; } public void doWork() { wiresharkFileList = new List&lt;WiresharkFile&gt;(); _currentFileNum = 1; _shouldContinue = true; _tokenSource = new CancellationTokenSource(); var token = _tokenSource.Token; Task.Factory.StartNew(() =&gt; { try { Parallel.ForEach(_source, new ParallelOptions { MaxDegreeOfParallelism = _parallelThreads //limit number of parallel threads }, file =&gt; { if (token.IsCancellationRequested) return; processFile(file, _selectedOutputDevice, _speed); _currentFileNum++; }); } catch (Exception) { } }, _tokenSource.Token).ContinueWith( t =&gt; { _loopCount++; if (continueAnotherLoop()) doWork(); else OnFinishPlayEvent(); } , TaskScheduler.FromCurrentSynchronizationContext() //to ContinueWith (update UI) from UI thread ); } private void processFile(string file, PacketDevice selectedOutputDevice, double speed) { Capinfos fileDetails = getFileDetails(file); WiresharkFile wiresharkFile = new WiresharkFile(); wiresharkFileList.Add(wiresharkFile); wiresharkFile.startTimerEvent += wf_startTimerEvent; wiresharkFile.stopTimerEvent += wf_stopTimerEvent; wiresharkFile.statusChangedEvent += wf_statusChangedEvent; FileDetailsEvent(new FileInfo(file).Name, fileDetails.packets, fileDetails.duration); wiresharkFile.sendBuffer(file, selectedOutputDevice, speed, fileDetails.packets); } private Capinfos getFileDetails(string file) { Capinfos details = new Capinfos(); details.readNumberOfPackets(file); details.readFileDuration(file); return details; } private void wf_statusChangedEvent(WiresharkFile wiresharkFile) { statusChangedEvent(wiresharkFile); } public int currentFileNum { get { return _currentFileNum; } } private bool continueAnotherLoop() { if (_loopCount &lt; _loops) return true; else return false; } } } </code></pre> <p>This class has <code>StatusChangedEvent</code> that pass to my form my current <code>WiresharkFile</code> object in order to update all my label (WiresharkFile class has several properties)</p> <p>And this is the event in the form that start timer and update my GUI every 200 milliseconds:</p> <pre><code>Timer timerPacket; private void job_startTimerEvent(WiresharkFile wiresharkFile) { timerPacket.Tag = wiresharkFile; if (InvokeRequired) this.Invoke((MethodInvoker)delegate { timerPacket.Start(); }); else { timerPacket.Start(); } } </code></pre> <p>now everything works fine and all my labels updated but i have strange bug: if i choose several file everything works fine but in case i choose for example 1 file and choose to play this file twice the first iteration works perfect but in the seconds iteration my timer not started although i did not stop the timer </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload