c# - Progress Bar in WPF - stuck in 50% -


so have class backgroundworker , progressbar on gui this

public class mcrypt {    public byte[] datablock;    public byte[] ivblock;    public static bitmap fingerprintimg;    public byte[] tempx;    public byte[] tempangles;    public byte[] tempy;    public byte[] tempkey;    public byte[] x;    public byte[] y;    public byte[] angles;    public byte[] key;    public int nom;     public mcrypt(backgroundworker bw, string imgloc, string fileloc, byte[] ivblock)    {       if (!bw.cancellationpending)       {          bw.reportprogress(0);          loadimg(imgloc);          bw.reportprogress(7);          detectminutiae(fingerprintimg);          bw.reportprogress(25);          convertvalues();          bw.reportprogress(30);          loadfile(fileloc);          // loadfile method contains datablock = file.readallbytes(fileloc);          bw.reportprogress(35);          handlelength(ivblock);          bw.reportprogress(40);          manageinitkey();          bw.reportprogress(45);          generatekey();          bw.reportprogress(50);       }    }     public byte[] encryptfile(backgroundworker bgw)    {       if(!bw.cancellationpending)       {          for(int = 0, < (datablock.length / 16), i++)          {             //doing cryptographical process here             ...             //progressbar updates             if((i / (datablock.length / 16)) + 50 != 100)                bgw.reportprogress((i / (datablock.length / 16)) + 50);             else                bgw.reportprogress(100);          }       }    } } 

as tried run app, progressbar updates when constructor runs. leaving progressbar in 50% state until process finish. don't understand why didn't work. idea? in advance

you're not using backgroundworker correctly, , you're locking ui thread.

move calls loadimg(), loadfile(); , reportprogress() dowork event. also, may have modify methods doing, if touch ui @ all.

i'd recommend reading this: threading in c#: backgroundworker


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -