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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:50:14+00:00 2026-06-10T08:50:14+00:00

I have a button that on click event I get some information from the

  • 0

I have a button that on click event I get some information from the network.

When I get information I parse it and add items to ListBox. All is fine, but when I do a fast double-click on button, it seems that two background workers are running and after finishing all work, items in the list are dublicated.

I want to do so that if you click button and the proccess of getting information is in work, this thread is stopping and only after first work is completed the second one is beginning.
Yes, I know about AutoResetEvent, but when I used it it helped me only one time and never more. I can’t implement this situation and hope that you will help me!

Now I even try to make easier but no success 🙁 : I added a flag field(RefreshDialogs)(default false), when the user clicks on button, if flag is true(it means that work is doing), nothing is doing, but when flag field is set to false, all is fine and we start a new proccess.
When Backgroundwork completes, I change field flag to false(it means that user can run a new proccess).

    private void Message_Refresh_Click(object sender, EventArgs e)
    {
        if (!RefreshDialogs)
        {
            RefreshDialogs = true;
            if (threadBackgroundDialogs.WorkerSupportsCancellation)
            {
                threadBackgroundDialogs.CancelAsync();
            }
            if (!threadBackgroundDialogs.IsBusy)
            {
                downloadedDialogs = 0;
                threadBackgroundDialogs = new BackgroundWorker();
                threadBackgroundDialogs.WorkerSupportsCancellation = true;
                threadBackgroundDialogs.DoWork += LoadDialogs;
                threadBackgroundDialogs.RunWorkerCompleted += ProcessCompleted;
                threadBackgroundDialogs.RunWorkerAsync();
            }
        }
    }
    void ProcessCompleted(object sender,  RunWorkerCompletedEventArgs e)
    {
        RefreshDialogs = false;
    }
  • 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-10T08:50:15+00:00Added an answer on June 10, 2026 at 8:50 am

    I’m not an Windows Phone expert, but as I see it has support for TPL, so following code would read nicely:

    private object syncRoot =new object();
    private Task latestTask;
    
    public void EnqueueAction(System.Action action)
    {
        lock (syncRoot)
        {
            if (latestTask == null)
                latestTask = Task.Factory.StartNew(action);
            else
                latestTask = latestTask.ContinueWith(tsk => action());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button click event that takes information from controls and enters it
I have a local thread that is started on button-click event from the main
I have a button click event handler with a switch case in it that
I have event Button that creates text box in run time. Private Sub Button1_Click(ByVal
I have a button that plays an audio file on its click listener. If
okay? I have a button that is inside an updatepanel, click on this button
I have a submit button when i click on that button i am having
Suppose, I want to have a link or a button that when user click
I have an ASP.NET form (C#) but which I click this button that should
I have a problem that when I click on the image button instead of

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.