private void bw_DoWork(object sender, DoWorkEventArgs e)
        {

            Byte[] result = new Byte[10000];
            BackgroundWorker worker = sender as BackgroundWorker;

            ThreadArguments ta = e.Argument as ThreadArguments;

            int resLen = Scanner.MWBscanGrayscaleImage(ta.pixels, ta.width, ta.height, result);

            //ignore positive result if closing is in progress
            if (isClosing)
            {
                resLen = -1;
            }

            if (resLen > 0 && resultDisplayed)
            {
                resLen = -1;
            }

            MWResult mwResult = null;

            if (resLen > 0 && Scanner.MWBgetResultType() == Scanner.MWB_RESULT_TYPE_MW)
            {
                MWResults results = new MWResults(result);

                if (results.count > 0)
                {
                    mwResult = results.getResult(0);
                    result = mwResult.bytes;
                }

            }

            if (lastTime != null && lastTime.Ticks > 0)
            {
                long timePrev = lastTime.Ticks;
                long timeNow = DateTime.Now.Ticks;
                long timeDifference = (timeNow - timePrev) / 10000;
                //System.Diagnostics.Debug.WriteLine("frame time: {0}", timeDifference);

            }

            lastTime = DateTime.Now;
            //ignore results shorter than 4 characters for barcodes with weak checksum
             if (mwResult != null && mwResult.bytesLength > 4 || (mwResult != null && mwResult.bytesLength > 0 && mwResult.type != Scanner.FOUND_39 && mwResult.type != Scanner.FOUND_25_INTERLEAVED && mwResult.type != Scanner.FOUND_25_STANDARD))
            {

                Scanner.MWBsetDuplicate(mwResult.bytes, mwResult.bytesLength);
				resultDisplayed = true;
                String typeName = BarcodeHelper.getBarcodeName(mwResult);

                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    BarcodeHelper.scannerResult = new ScannerResult();

                    BarcodeHelper.resultAvailable = true;
                    BarcodeHelper.scannerResult.code = mwResult.text;
                    BarcodeHelper.scannerResult.type = BarcodeHelper.getBarcodeName(mwResult);
                    BarcodeHelper.scannerResult.isGS1 = mwResult.isGS1;
                    if (mwResult.locationPoints != null) {
                        BarcodeHelper.scannerResult.location = "{\"p1\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p1.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p1.y) + "},"
                          + "\"p2\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p2.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p2.y) + "},"
                          + "\"p3\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p3.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p3.y) + "},"
                          + "\"p4\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p4.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p4.y) + "}}";

                    }
                    else
                    {
                        BarcodeHelper.scannerResult.location = "false";
                    }

                    BarcodeHelper.scannerResult.imageWidth = mwResult.imageWidth;
                    BarcodeHelper.scannerResult.imageHeight = mwResult.imageHeight;

                    Byte[] binArray = new Byte[mwResult.bytesLength];
                    for (int i = 0; i < mwResult.bytesLength; i++)
                        binArray[i] = mwResult.bytes[i];


                    BarcodeHelper.scannerResult.bytes = binArray;

                    stopCamera();
                    
                    string resultString = "{\"code\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.code) + ","
                    + "\"type\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.type) + ","
                    + "\"bytes\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.bytes) + ","
                    + "\"isGS1\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.isGS1) + ","
                    + "\"location\":" + BarcodeHelper.scannerResult.location + ","
                    + "\"imageWidth\":" + BarcodeHelper.scannerResult.imageWidth + ","
                    + "\"imageHeight\":" + BarcodeHelper.scannerResult.imageHeight
                    + "}";
                    PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString);
                    pResult.KeepCallback = true;
                    MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID);
                     if (param_CloseScannerOnDecode)
                     {
                         isClosing = true;
                         if (isPage) { 
                            NavigationService.GoBack();
                         }
                         else
                         {
                             MWBarcodeScanner.mwbScanner.stopScanner("");
                         }
                         resultDisplayed = false;

                     }

                    isProcessing = false;
                });


            }
            else
            {
                isProcessing = false;
            }
            activeThreads--;

        }
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {

            Byte[] result = new Byte[10000];
            BackgroundWorker worker = sender as BackgroundWorker;

            ThreadArguments ta = e.Argument as ThreadArguments;

            int resLen = Scanner.MWBscanGrayscaleImage(ta.pixels, ta.width, ta.height, result);

            //ignore positive result if closing is in progress
            if (isClosing)
            {
                resLen = -1;
            }

            if (resLen > 0 && resultDisplayed)
            {
                resLen = -1;
            }

            MWResult mwResult = null;

            if (resLen > 0 && Scanner.MWBgetResultType() == Scanner.MWB_RESULT_TYPE_MW)
            {
                MWResults results = new MWResults(result);

                if (results.count > 0)
                {
                    mwResult = results.getResult(0);
                    result = mwResult.bytes;
                }

            }

            if (lastTime != null && lastTime.Ticks > 0)
            {
                long timePrev = lastTime.Ticks;
                long timeNow = DateTime.Now.Ticks;
                long timeDifference = (timeNow - timePrev) / 10000;
                System.Diagnostics.Debug.WriteLine("frame time: {0}", timeDifference);

            }

            lastTime = DateTime.Now;
            //ignore results shorter than 4 characters for barcodes with weak checksum
             if (mwResult != null && mwResult.bytesLength > 4 || (mwResult != null && mwResult.bytesLength > 0 && mwResult.type != Scanner.FOUND_39 && mwResult.type != Scanner.FOUND_25_INTERLEAVED && mwResult.type != Scanner.FOUND_25_STANDARD))
            {
                resultDisplayed = true;
                String typeName = BarcodeHelper.getBarcodeName(mwResult);

                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    isClosing = true;
                    BarcodeHelper.scannerResult = new ScannerResult();

                    BarcodeHelper.resultAvailable = true;
                    BarcodeHelper.scannerResult.code = mwResult.text;
                    BarcodeHelper.scannerResult.type = BarcodeHelper.getBarcodeName(mwResult);
                    BarcodeHelper.scannerResult.isGS1 = mwResult.isGS1;

                    Byte[] binArray = new Byte[mwResult.bytesLength];
                    for (int i = 0; i < mwResult.bytesLength; i++)
                        binArray[i] = mwResult.bytes[i];


                    BarcodeHelper.scannerResult.bytes = binArray;
                    stopCamera();
                    NavigationService.GoBack();

                    isProcessing = false;
                    resultDisplayed = false;
                });


            }
            
           
            else
            {
                
                isProcessing = false;
                
              
            }
            activeThreads--;

        }