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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:35:30+00:00 2026-06-07T22:35:30+00:00

I have a button which initiates a connection between the program and a machine

  • 0

I have a button which initiates a connection between the program and a machine known as DDC. To prevent the UI thread from being locked while the connection is being established, I naturally create a backgroundworker to handle the job.

The problem is this: In the event where the client doesn’t get any response from the DDC, the client has to wait for 30 seconds before giving a timeout. More precisely speaking, the thread halts executing on the line “GetLogicStatusListResponse result = ddcdao.GetLogicStatusList();”.

I’d like the user to be able to cancel the operation if a button has been clicked on the program, but as far as I know there is no way to abort backgroundworker and cancellation wouldn’t really help me here since the thread is locked for 30 seconds before the code can even check if cancellationpending is true or not.

I would like to hear some ideas to properly implement the cancellation feature so that the user may start/stop the connection whenever he/she wishes to.

private void bwWorkerConnect_DoWork(object sender, DoWorkEventArgs e)
        {
            //Branch in only if the DDC returns a ping response
            if (DDCGlobal.DDCPingTest(ddc))
            {
                try
                {
                    //Creates an object of class which communicates with the engine
                    //Retrieves the object obtained through remoting (Engine) 
                    //and casts it to a ReqDDCLogicListResponse type (See CommonEngine)
                    DDCDAO ddcdao = new DDCDAO(DDCGlobal.ddcEngineIP, ddc.Ip);

                    //Request status list from DDC (TIMEOUT = 30 SECONDS)
                    GetLogicStatusListResponse result = ddcdao.GetLogicStatusList();
               ...
            if (bwWorkerConnect.CancellationPending)
            {
                e.Cancel = true;
            }



    public void LogicListLoad()
    {
        if (!bwWorkerConnect.IsBusy)
            bwWorkerConnect.RunWorkerAsync();
        else
        {
            MessageBox.Show(UIConstant.DDC_CONNECT_ALREADY_WARNING);
        }

    }
  • 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-07T22:35:33+00:00Added an answer on June 7, 2026 at 10:35 pm

    Posting my comment as answer for future reference.

    You can approach your issue with a second BackgroundWorker running alongside the first, which only polls a flag in the first one to verify its status: since he’s independent, it doesn’t have to “wait” and is free to kill the first worker in case it gets stuck.

    This should be deadlock-free since the second worker does nothing more than a periodic “health check” of the first worker as long as the flag handling instructions are wrapped up in a lock.

    Flow would look like this:

    • When you need a connection, fire up both workers
    • First worker proceeds to attempt the connection, sets a flag to notify the outer world its “connecting” status
    • Second worker might check the first worker status every second 30 times: if it never reads anything different from “connecting” it can proceed and kill the first worker. It might also react to user input and kill the first worker before time (ie. any user input cancels the second worker, which in turn can kill the first one before its own demise).
    • Flow end
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my C# program, I have a thread that represents a running test, which
I have button which post values of form to url but during post i
I have a button which on Click loads another activity, but before it loads
I have a button which creates form elements on click . My addelement function
I have a button which needs to get created dynamically but the problem is
I have a button which is in update panel. When I click on button
I have a button which opens a context menu with a list of various
I have a button which creates a div. Once clicked I would like to
I have a Button which when clicked will execute an addQty method and in
I have this button which is not working correctly for hold button for a

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.