Avatar of phenryll
phenryll

asked on 

How to make my applz delegate-oriented?

Hi Experts,

I'd like to make an application fully delegate-oriented. I am reading some good books related to that subject but the topic deserves to be said "Advanced .NET topic" :)
The application is intended to:
- read an xml file and wraps data into a business model class
      <Songs>
            <Song name="name1" date="date1"/>
            <Song name="name2" date="date2"/>            
      </Songs>
      
      Let's called this business class "SongElement"
      The properties : Name, date
      
- Make a list of all the music I have by looping over the files in my hard drive
      The business object is "MusicFile"
      The properties: Name, Size, Date, Path
      
- Update my XML's attributes on the basis of the information retrieved from the hard drive.

- Everything is centralized in the core class : Perform class

- I'd like to make the operations working asynchronously because there is apparently no good readon to use only one thread.
        

There are 2 delegates that are declared at the top-level and 2 events declared inside the Perform class

    public delegate List<MusicFile> MakeMusicFileList();
    public delegate List<SongElement> MakeSongElementList();

      public event MakeMusicFileList ListMusicFiles;
    public event MakeSongElementList ListSongElements;
      
My questions are:

- Do I have to declare the delegates in a different way? Is the type correct for the purpose?
- Would List<T> be a better choise? If so, how can I use the BeginInvoke and the EndInvoke?
      I can call the GetInvocationList() from my unique delegate ; but how can I distinct the different object returned?
- Any other idea to make the logic more accurate ?


Thanks a lot for your help.

Regards,
public delegate List<MusicFile> MakeMusicFileList();
    public delegate List<SongElement> MakeSongElementList();
 
    public class MusicFile 
    {
        public static List<MusicFile> List()
        {
            return new List<MusicFile> () ;
        }
    }
    public class SongElement
    {
        public static List<SongElement> List()
        {
            return new List<SongElement>();
        }
    }
    public class Perform
    {
        public event MakeMusicFileList ListMusicFiles;
        public event MakeSongElementList ListSongElements;
        public void DoPerform()
        {
            List<MusicFile> musicFiles = null;
            List<SongElement> songElements = null;
 
            if (this.ListMusicFiles != null)
                musicFiles = this.ListMusicFiles();
 
            if (this.ListSongElements != null)
                songElements = this.ListSongElements();
 
            //how to make the delagates working asynchronously with BeginInvoke() and EndInvoke?
 
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Perform p = new Perform();
            p.ListMusicFiles += MusicFile.List;
            p.ListSongElements += SongElement.List;
            p.DoPerform();
        }
    }

Open in new window

.NET Programming

Avatar of undefined
Last Comment
elimesika

8/22/2022 - Mon