Click here to Skip to main content
15,900,725 members
Home / Discussions / C#
   

C#

 
QuestionIs streamreader slow compared to other text import functions? Pin
turbosupramk33-May-13 3:42
turbosupramk33-May-13 3:42 
AnswerRe: Is streamreader slow compared to other text import functions? Pin
GuyThiebaut3-May-13 4:21
professionalGuyThiebaut3-May-13 4:21 
GeneralRe: Is streamreader slow compared to other text import functions? Pin
turbosupramk33-May-13 4:51
turbosupramk33-May-13 4:51 
AnswerRe: Is streamreader slow compared to other text import functions? Pin
Pete O'Hanlon3-May-13 4:24
mvePete O'Hanlon3-May-13 4:24 
GeneralRe: Is streamreader slow compared to other text import functions? Pin
turbosupramk33-May-13 5:13
turbosupramk33-May-13 5:13 
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 
I'm trying to add an interface, but it's causing havoc with my ProgressBar update events (My progress bar event is null so my progress bar never gets updated). I have the following older link about it: [^]

The progress bar works where it doesn't use events in Generic, but it's not working where I'm using the events in CR5_new and CR5_Comm. As you can see below, when I get to RaiseProgressChange in my CR5_new class, the event is null. I can't figure out why it's null. I'm not very good with events, and throwing in the interface (the iCR_Comm interface is new) doesn't help, since I'm not very good at interfaces either. I removed unrelated code, so hopefully this post isn't missing important definitions. I realize that this doesn't look familiar to you and is a lot of info, but any help would be appreciated. If anyone is mean, I'm not going to upvote that comment. There are very specific project related reasons that these are all separate vs projects. (re-use, multiple CRx's, multiple CRx_comm's, and numerous dynamic data classes that give extra control info to the Generic class.) Everything works (programming, write, read, through CR5_Comm class), so don't focus on that. It's just the events that update the progress bar that don't work. Names of classes have been changed enough that they don't give away our information, but still resemble my code.

My code looks like this now (all separate vs projects):

vs project: crTool
frmUserForm.cs:
C#
using USB_Comm;
namespace CRWriter
{
  public partial class frmUser:Form
  {
  public frmUser(string dllSelected, TemplateHandlerApplication.Templates.TEMPL[] template, string dll, Site.Site.SITE cert0)
  {
         programDll = dllSelected;
         templateArr = template;
         itsDll = dll;
         cert = cert0;
         InitializeComponent();
         CreateSubForms();   //start here
  }
  private void CreateSubForms()
  {
    cb = new CrComm();
    int errValue = cb.FindUsbHid(ref HWndBoxID); //see how many boxes there are
    for (int i = 0; i < cb.cbInfos.Length; i++)
    {
       iCRComm cb1 = null;
        if (controls[i] == null)
        {   
           CRComm_Factory.CRCommFactory factory = new  CRComm_Factory.CRCommFactory();
           int type = factory.DetermineCR_Type(programDll);
           try
           {
              cb1 = factory.GetCRComm(type);//iCrComm cb1 = factory.GetCR(type);
              controls[i] = gen.GetProgramControl(cb1, programDll, templateArr, itsDll, cert, i, cb1.GetBoxID(i), this);
            }
...
         }
      }
  }
 }
}


vs project: Generic
GenericPC.cs
C#
using USB_Comm;
namespace GenericCW
{
  public partial class GenericPC: UserControl
  {
    public GenericPC() {InitializeComponent();}
    public Control GetPC(iCRComm cbInstance, string dllSelected, TemplateHandlerApp.Templates.TEMPL[] template, string dll, Site.Site.SITE cert0, int slaveIndex, int boxID, Form theParent)
    {
           //cr = new CR5_new.CR5(slaveIndex);
           cr = factory.GetCR(type, slaveIndex);
           cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
    }
    private int writeResultCheck(byte []  writeDat, byte [] statusDat, byte [] dataDumpWriteCheck)
   {
        for (int count = 0; ((count < max) && (!done)); count++)
        {
            if(((count % 24) == 0) || (count == max-1))
               updateProgressBar(count, SlaveIndex); //this works
            }
        }
    }
    private void updateProgressBar(int n, int id)
    {
       if (id == SlaveIndex) //make sure it's our progress bar and not the other one
       {
           pb_Progress.BeginInvoke(
              new Action(() =>
              {
                 pb_Progress.Value = n;
              }
           ));
       }
    }
  }
}


vs project: cr5_new
CR5_new.cs:
C#
using USB_Comm;
namespace CR5_new
{
    public class CR5:iCR
    {
        [STAThread]
        static void Main()
        {
        }
        public event ProgressChangeHandler2 ProgressChanged;
        //constructor
        public CR5(int slaveIndex)
        {
           SlaveIndex = slaveIndex;
        }
        public int ProcessTagWrite(ref byte[] WriteDat, bool isFastProgramMode)
        {
           AttemptWrites();
        }
        private int AttemptWrites()
        {
           for (int i = 0; i < (max); i++)
           {
                //update Progress Bar every 28
                if (((i % 28) == 0) || (i == max-1))
                   RaiseProgressChange(i, SlaveIndex);
           }
         }
        private void RaiseProgressChange(int progress, int id)
        {
            if (ProgressChanged != null) //this is null
            {
                ProgressChanged(progress, id);  //not getting here
            }
        }


vs project: icr
iCR.cs:
using USB_Comm;
public interface iCR
{
            event ProgressChangeHandler2 ProgressChanged;
...
}


vs project: icrComm
iCRComm.cs:
C#
public delegate void ProgressChangeHandler2(int progress, int id);
public interface iCRComm
{
    event ProgressChangeHandler2 ProgressChanged;
    int ReadTag(ref byte[] dataDumpWriteCheck);
}


vs project: cr5_comm_new
CR5_Comm.cs:
C#
namespace USB_Comm
{
   public class CrComm:iCRComm
   {
        public event ProgressChangeHandler2 ProgressChanged;

        private void RaiseProgressChange(int progress, int id)
        {
            if (ProgressChanged != null)
            {
                ProgressChanged(progress, id);  //prog bar not updating from here either
            }
        }
        public int ReadTag(ref byte[] byteData, int usbIndex)
        {
            for (int cell = 0; cell < max; cell++)
            {
                //only update progress bar every 28
                if (((cell % 28) == 0) || (cell == max-1))
                {
                    RaiseProgressChange(cell, usbIndex);
                }
            }
         }
    }
  }
}
}

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 
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 

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.