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

  • Home
  • SEARCH
  • 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 941103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:03:55+00:00 2026-05-15T22:03:55+00:00

How should I check for a CancellationPending within a BackgroundWorker DoWork method, when within

  • 0

How should I check for a CancellationPending within a BackgroundWorker DoWork method, when within this method I call off to a Pcap.Net packet capture routine, which responses via a callback. The two options I can think of is:

a) write a loop at the bottom of the DoWork method to continually check for CancellationPending

b) put the check in the callback method I wrote which Pcap.Net will call back into – but no doubt the potential issue here is the cancellation can’t work then until another patch match occurs and there is a callback

suggestions?

public class MainClass {
       private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
       {
            var worker = sender as BackgroundWorker;
            _packetCapturer = new PacketCapturer();
        }

}

    public class PacketCapturer

      public PacketCapturer() {
         // Start Capture Here
         // Opens PacketCommunicator
         // communicator.ReceivePackets(0, PacketCapturerCallback);

      }

      private static void PacketCapturerCallback(Packet packet) {
         // Deal with returned packet

      }

    }
  • 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-05-15T22:03:56+00:00Added an answer on May 15, 2026 at 10:03 pm

    You don’t need a BGW if you use the OnPacketArrival event. Makes it easy to stop, just call StopCapture().

    The other way, GetNextPacket() does need a BGW. You have to open the device with a read timeout that short enough so you can see the CancellationPending flag quick enough. You’ll also have to deal with the overhead of getting it displayed on your UI, ReportProgress is not cheap. And freezes the UI when you call it more often than ~1000 times per second.

    I wonder if we’re talking about the same library…

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

Sidebar

Related Questions

I have this Dispose method I want to change. (Yeah I should check every
I've written this method which should check for file changes. public static void watch()
This simple script should theoretically check the form for errors and then print any
this is my first question here :) I know that I should not check
(New to ASP.NET here.) I have a user control which should check for a
This program should check whether the value of getTotalCount() is greater thana a number
I have a java method that should check through an ArrayList and check if
From what I've read, this is how I should check for any records... v
I got this code in one of my methods. It should check if the
i should check whether there is some values based on this condition. if there

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.