Click here to Skip to main content
15,888,205 members
Home / Discussions / C#
   

C#

 
AnswerRe: Is streamreader slow compared to other text import functions? Pin
turbosupramk33-May-13 5:14
turbosupramk33-May-13 5:14 
GeneralRe: Is streamreader slow compared to other text import functions? Pin
DaveyM693-May-13 13:47
professionalDaveyM693-May-13 13:47 
QuestionEvent/Delegate for progress bar issue Pin
MichCl3-May-13 3:13
MichCl3-May-13 3:13 
AnswerRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen3-May-13 7:21
professionalEddy Vluggen3-May-13 7:21 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 7:31
MichCl3-May-13 7:31 
AnswerRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen3-May-13 8:29
professionalEddy Vluggen3-May-13 8:29 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 8:39
MichCl3-May-13 8:39 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen3-May-13 8:53
professionalEddy Vluggen3-May-13 8:53 
To use the other interface, the CR5 class would need to inherit from it and implement it.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationXXIV
{
    enum CRType { CR5, CR6 }
    public delegate void ProgressChangeHandler2(int progress, int id);
    public interface iCRComm
    {
        event ProgressChangeHandler2 ProgressChanged;
        int ReadTag(ref byte[] dataDumpWriteCheck);
    }
    public class CR5 : iCRComm
    {
        public int SlaveIndex { get; set; }
        public event ProgressChangeHandler2 ProgressChanged;
        public CR5(int slaveIndex)
        {
            SlaveIndex = slaveIndex;
        }
        public int ReadTag(ref byte[] dataDumpWriteCheck)
        {
            Console.WriteLine(String.Format("Data: {0}", dataDumpWriteCheck));
            return 0;
        }
        private void RaiseProgressChange(int progress, int id)
        {
            if (ProgressChanged != null) //this is null
            {
                ProgressChanged(progress, id);  //not getting here
            }
        }
    }
    class GenericPC
    {
        public iCRComm GetPC()
        {
            var cr = Program.GetCR(CRType.CR5, 0);
            cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
            byte[] b = null;
            cr.ReadTag(ref b);
            return cr;
        }

        private void updateProgressBar(int n, int id)
        {
            Console.WriteLine(String.Format("Progress: {0}\tid:{1}", n, id));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var npc = new GenericPC();
            npc.GetPC();
            Console.ReadKey();
        }

        public static iCRComm GetCR(CRType type, int slaveIndex)
        {
            iCRComm cr = null;
            switch (type)
            {
                case CRType.CR5:
                    cr = new CR5(slaveIndex);
                    break;
                case CRType.CR6:
                    cr = null; //new CR6(slaveIndex);
                    break;
                default:
                    throw new ArgumentException(string.Format("A CR of type {0} cannot be found", Enum.GetName(typeof(CRType), type)));
            }
            return cr;
        }
    }
}

Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 9:22
MichCl3-May-13 9:22 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 9:25
MichCl3-May-13 9:25 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen3-May-13 9:40
professionalEddy Vluggen3-May-13 9:40 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 9:48
MichCl3-May-13 9:48 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen4-May-13 0:41
professionalEddy Vluggen4-May-13 0:41 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl6-May-13 3:40
MichCl6-May-13 3:40 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen6-May-13 7:52
professionalEddy Vluggen6-May-13 7:52 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl6-May-13 9:19
MichCl6-May-13 9:19 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl7-May-13 2:09
MichCl7-May-13 2:09 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen7-May-13 3:16
professionalEddy Vluggen7-May-13 3:16 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl7-May-13 3:55
MichCl7-May-13 3:55 
GeneralRe: Event/Delegate for progress bar issue Pin
Eddy Vluggen7-May-13 9:04
professionalEddy Vluggen7-May-13 9:04 
GeneralRe: Event/Delegate for progress bar issue Pin
MichCl3-May-13 8:49
MichCl3-May-13 8:49 
QuestionHow to view the images from folder one by one Pin
9,937,550 members2-May-13 20:04
professional9,937,550 members2-May-13 20:04 
AnswerRe: How to view the images from folder one by one Pin
OriginalGriff2-May-13 21:34
mveOriginalGriff2-May-13 21:34 
GeneralRe: How to view the images from folder one by one Pin
9,937,550 members3-May-13 2:13
professional9,937,550 members3-May-13 2:13 
AnswerRe: How to view the images from folder one by one Pin
abdussalam1433-May-13 3:15
professionalabdussalam1433-May-13 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.