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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:25:35+00:00 2026-06-13T06:25:35+00:00

Hey I have this test back ground worker which seems to get stuck on

  • 0

Hey I have this test back ground worker which seems to get stuck on the DoWork method or maybe the RunWorkerCompleted is not being fired can you guys see anything wrong here?

Maybe I am not implementing this properly :/

 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;

        using System.Threading.Tasks;
        using System.Windows.Forms;
        using MailChimp;
        using System.Threading;
        using System.Runtime.InteropServices;

        namespace Chimporter
        {
            public partial class Form1 : Form
            {
                //Worker thread flag set to false
                static bool done = false;
                //Console dll
                [DllImport("Kernel32.dll")]
                static extern Boolean AllocConsole();

                public Form1()
                {
                    InitializeComponent();
                }

                private void button1_Click(object sender, EventArgs e)
                {

                }

                private void label1_Click(object sender, EventArgs e)
                {

                }



                private void accountInformationToolStripMenuItem_Click(object sender, EventArgs e)
                {
                    //loadWindow pleaseWait = new loadWindow();
                    //pleaseWait.Show();
                    BackgroundWorker bg = new BackgroundWorker();
                    bg.DoWork += new DoWorkEventHandler(bg_DoWork);
                    bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
                    bg.RunWorkerAsync();
                    while (!done)
                    {
                        //Console.WriteLine("Waiting in Main, tid " + Thread.CurrentThread.ManagedThreadId);
                        //Thread.Sleep(100);

                    }
                    //AccountInfo accInfo = new AccountInfo();
                    //accInfo.Show();

                }

                public void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
                {
                    if (!AllocConsole())
                    {
                        Console.WriteLine("Fnished! " + Thread.CurrentThread.ManagedThreadId);
                    }
                    done = true;
                }

                public void bg_DoWork(object sender, DoWorkEventArgs e)
                {
                    for (int i = 0; i <= 3; i++)
                    {
                        if (!AllocConsole())
                        {
                            Console.WriteLine("Work Line: " + i + ", tid " + Thread.CurrentThread.ManagedThreadId);
                            Thread.Sleep(500);
                        }                
                    }            
                    //string key = "e42713458882f6c2c27b3d6d951174a2-us6";
                    //var mc = new MCApi(key, true);
                    //string user = mc.GetAccountDetails().Username.ToString();
                    return;
                }

                private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
                {

                }

                private void exitToolStripMenuItem_Click(object sender, EventArgs e)
                {
                    //Exit application Form.Close()
                    Application.Exit();
                }
            }
        }
  • 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-13T06:25:36+00:00Added an answer on June 13, 2026 at 6:25 am

    Take your while (!done) out. It is locking up the main thread. The worker completed event gets raised on that thread, but since it is busy in a loop it will never get raised.

    The whole point of the RunWorkerCompleted event is so that you get a notification on the main thread and you don’t have to lock it up in a busy loop and make your gui unresponsive.

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

Sidebar

Related Questions

Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey guys I simply cannot get this to work. I have some content that
If I have this code: array(0 => hey, 1 => bla, 2 => test,
If I have this array: array( hey , bla , test); and I want
Let's say I have this: test = function() { this.init = function() { $(#someElement).html(Hey!).mousedown(function()
I have a string of test like this: <customtag>hey</customtag> I want to use a
Hey I have this code but it doesn't work because it is expecting a
Hey all, I'm about to rip my hair out. I have this client that
hey guys having this really simple problem but cant seem to figure out have
Hey this is the weirdest problem i've ever encoutered, I have 2 projects that's

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.