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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:31:37+00:00 2026-05-14T16:31:37+00:00

The following code is a silverlight application but the same happens in WPF, so

  • 0

The following code is a silverlight application but the same happens in WPF, so it seems to be just something I’m missing regarding the delegate, event, etc.

Can anyone tell me why the following code successfully executes this event:

OnLoadingComplete(this, null);

but never executes this event handler?

void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args)

CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Diagnostics;

namespace TestEvent22928
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            DataLoader initialDataLoader = new DataLoader("initial");
            initialDataLoader.RegisterText("test1", "http://test:111/testdata/test1.txt");
            initialDataLoader.RegisterText("test2", "http://test:111/testdata/test2.txt");
            initialDataLoader.BeginLoading();
            initialDataLoader.OnLoadingComplete += new DataLoader.LoadingComplete(initialDataLoader_OnLoadingComplete);
        }

        void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args)
        {
            Debug.WriteLine("loading complete"); //WHY DOES EXECUTION NEVER GET HERE?
        }
    }


    public class DataManager
    {
        public DataLoader CreateDataloader(string dataloaderIdCode)
        {
            DataLoader dataLoader = new DataLoader(dataloaderIdCode);
            return dataLoader;
        }
    }

    public class DataLoader
    {
        public string IdCode { get; set; }
        public List<DataItem> DataItems { get; set; }

        public delegate void LoadingComplete(object obj, DataLoaderArgs args);
        public event LoadingComplete OnLoadingComplete = delegate { };

        private int dataItemCurrentlyLoadingIndex;

        public DataLoader(string idCode)
        {
            IdCode = idCode;
            DataItems = new List<DataItem>();
            dataItemCurrentlyLoadingIndex = -1;
        }

        public void RegisterText(string idCode, string absoluteSourceUrl)
        {
            DataItem dataItem = new DataItem
            {
                IdCode = idCode,
                AbsoluteSourceUrl = absoluteSourceUrl,
                Kind = DataItemKind.Text
            };
            DataItems.Add(dataItem);
        }

        public void BeginLoading()
        {
            LoadNext();
        }

        private void LoadNext()
        {
            dataItemCurrentlyLoadingIndex++;
            if (dataItemCurrentlyLoadingIndex < DataItems.Count())
            {
                DataItem dataItem = DataItems[dataItemCurrentlyLoadingIndex];
                Debug.WriteLine("loading " + dataItem.IdCode + "...");
                LoadNext();
            }
            else
            {
                OnLoadingComplete(this, null); //EXECUTION GETS HERE
            }
        }
    }

    public class DataItem
    {
        public string IdCode { get; set; }
        public string AbsoluteSourceUrl { get; set; }
        public DataItemKind Kind { get; set; }
        public object DataObject { get; set; }
    }

    public enum DataItemKind
    {
        Text,
        Image
    }

    public class DataLoaderArgs : EventArgs
    {
        public string Message { get; set; }
        public DataItem DataItem { get; set; }

        public DataLoaderArgs(string message, DataItem dataItem)
        {
            Message = message;
            DataItem = dataItem;
        }
    }
}
  • 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-14T16:31:38+00:00Added an answer on May 14, 2026 at 4:31 pm

    You’re registering the handler only after you start loading:

            initialDataLoader.BeginLoading();
            initialDataLoader.OnLoadingComplete += new DataLoader.LoadingComplete(initialDataLoader_OnLoadingComplete);
    

    The way your code is currently written, it looks like BeginLoading() blocks until completion, which means the handler will never be called, as you don’t set it until after you’ve finished loading.

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

Sidebar

Related Questions

I have the following code in a click handler of a Silverlight application (4).
Given the Following Code how Would i Change/Set my Silverlight WCF Service URI in
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have the following Solution: SomeProject.Ria (non Silverlight code) SomeProject.Ria.Silverlight (Silverlight light code, namespace
Following code gets executed whenever I want to persist any entity. Things seems to
I'd like to use the built-in Silverlight 4.0 field validation on the following code,
I'm following this tutorial (beginner Hello World Silverlight Application) In this step it shows
I get the following error when I try to run my Silverlight application: Line:
Hi I am using http://silverlightpdf.codeplex.com/ code to print pdf from my silverlight application hosted
I have the following code to create an HttpWebRequest in my WP7 application. I'm

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.