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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:40:58+00:00 2026-05-25T02:40:58+00:00

I am adding some data to a list and it might take a while

  • 0

I am adding some data to a list and it might take a while to do this. Therefore i perform this action asynchronously. I do it like this:

ScanDelegate worker = StartScan;
AsyncCallback completedCallback = ScanCompletedCallback;
lock (_sync)
{
    var async = AsyncOperationManager.CreateOperation(null);
    worker.BeginInvoke(completedCallback, async);
}

The information added in StartScan() is correctly added to the list. When the scan is complete, i want to perform a different scan, depending on the data in the list. So i start the different scan in the ScanCompletedCallback() method. But at this point, my list is empty. Im guessing that this is because the callback method is invoked when the worker has been started, and not when it returns.

Is this true?

And if it is, how can i know when my worker has completed its tasks?

Edit: I can’t get my head around this. It doesn’t make sense. I came to think of the list i am adding to. I couldn’t just add to it, i had to wrap it in a Dispatcher thread. This must be the problem, right? Is there a way i can make my Async method StartScan() wait for this Dispatcher ?

Thanks in advance!

StartScan()

private void StartScan()
    {
        //For testing
        for (int t = 0; t < 1; t++)
        {
            var app2 = Application.Current;
            if (app2 != null)
            {
                app2.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new DispatcherOperationCallback(AddComputerToList),
                                            new ComputerModel()
                                                {
                                                    HostName = "Andreas-PC",
                                                    IpAddress = "192.168.1.99",
                                                    ActiveDirectoryPath = "ikke i AD",
                                                    Name = "Andreas-PC",
                                                    OperatingSystem = "Microsoft Windows 7 Enterprise"
                                                });
            }
        }
   }

ScanCompletedCallback()

        private void ScanCompletedCallback(IAsyncResult ar)
    {
        var worker = (ScanDelegate)((AsyncResult)ar).AsyncDelegate;
        var async = (AsyncOperation)ar.AsyncState;
        worker.EndInvoke(ar);
        lock (_sync)
        {
            IsScanning = false;
        }

        var completedArgs = new AsyncCompletedEventArgs(null, false, null);
        async.PostOperationCompleted(e => OnScanCompleted((AsyncCompletedEventArgs)e), completedArgs);
    }

AddComputerToList()

private object AddComputerToList(Object objComputer)
    {
        var computer = objComputer as ComputerModel;
        if (computer != null)
        {
            ComputersList.Add(computer);
            OnPropertyChanged("ComputersList");
        }
        return null;
    }
  • 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-25T02:40:59+00:00Added an answer on May 25, 2026 at 2:40 am

    As a direct answer to your question the callback will occur on completion of ScanCompletedCallback.

    If you have a list that you believe should have some data in it at this point then there appears to be something else wrong, posting some more code may help with this.

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

Sidebar

Related Questions

Looking at adding some data graphing to a new iPhone app in development (ala
//html structure <div id='outer'> <div id='inner'> </div> </div> I am adding some data to
I'm looking into adding some unit tests for some classes in my data access
I'm currently adding some new extended classes to this code: foreach (BaseType b in
We have an asp.NET page which is programmaticaly adding data as new list items
In Dreamweaver I have a list box or menu/list. I am dynamically adding data
I have some data that I want to present in a FlowDocument . This
Is there any way to get some list of all Sql Data Types on
I want brief knowledge about Data Template for Customizing a control(like Combo Box,List Box
I have a code that read list from some paged string data. What I

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.