private void PeriodicTimerCallback(ThreadPoolTimer timer)
        {
            if (_cancelRequested == false)
            {
                // get exclusive use of port
                _adapter.beginExclusive(true);

                // open a path to the temp device
                _path.open();

                // check if present
                if (_owc.Present)
                {
                    // read the temp device
                    byte[] state = _tc.readDevice();

                    _tc.doTemperatureConvert(state);

                    state = _tc.readDevice();

                    Debug.WriteLine("Temperature of " + _address + " is " + _tc.getTemperature(state) + " C");
                }
                else
                {
                    Debug.WriteLine("Device " + _address + " not present so stopping thread");
                }

                // close the path to the device
                _path.close();

                // release exclusive use of port
                _adapter.endExclusive();
            }
            else
            {
                _periodicTimer.Cancel();

                var settings = ApplicationData.Current.LocalSettings;
                var key      = _taskInstance.Task.Name;

                //
                // Write to LocalSettings to indicate that this background task ran.
                //
                settings.Values[key] = "Canceled with reason: " + _cancelReason.ToString();
                Debug.WriteLine("Background " + _taskInstance.Task.Name + settings.Values[key]);

                //
                // Indicate that the background task has completed.
                //
                _deferral.Complete();
            }
        }
    /// <summary>
    /// Search a given path for an XML file.
    /// </summary>
    /// <param name="currentPathIndex"> index into the 'paths' Vector that
    ///        indicates what 1-Wire path to search for XML files </param>
    /// <returns> true if the current path provided has been
    ///         completely checked for XML files.  false if
    ///         if this current path should be searched further </returns>
    public static bool pathXMLSearchComplete(int currentPathIndex)
    {
        OneWireContainer  owd = null, check_owd = null;
        ParseContainer    pc = null, check_pc = null;
        OWFileInputStream file_stream = null;
        bool rslt       = true;
        bool xml_parsed = false;

        try
        {
            main_Renamed.Status = "Waiting for 1-Wire available";

            // get exclusive use of adapter
            adapter.beginExclusive(true);

            main_Renamed.Status = "Exclusive 1-Wire aquired";

            // open the current path to the device
            OWPath owpath = (OWPath)paths[currentPathIndex];
            owpath.open();

            main_Renamed.Status = "Path opened: " + owpath.ToString();

            // setup search
            adapter.setSearchAllDevices();
            adapter.targetAllFamilies();
            adapter.Speed = DSPortAdapter.SPEED_REGULAR;

            // find all devices, update parseLog and get a device filesystem to check
            for (System.Collections.IEnumerator owd_enum = adapter.AllDeviceContainers; owd_enum.MoveNext();)
            {
                owd = (OneWireContainer)owd_enum.Current;
                long key = owd.AddressAsLong;

                main_Renamed.Status = "Device Found: " + owd.AddressAsString;

                // check to see if this is in the parseLog, add if not there
                pc = null;
                parseLog.TryGetValue(key, out pc);
                if (pc == null)
                {
                    main_Renamed.Status = "Device is new to parse: " + owd.AddressAsString;
                    pc = new ParseContainer(owd);
                    parseLog.Add(key, pc);
                }
                else
                {
                    main_Renamed.Status = "Device " + owd.AddressAsString + " with count " + pc.attemptCount;
                }

                // if attemptCount is low then check it later for XML files
                if (pc.attemptCount < ParseContainer.MAX_ATTEMPT)
                {
                    check_owd = owd;
                    check_pc  = pc;
                }
            }

            // check if there is anything to open
            if (check_owd != null)
            {
                // result is false because found something to try and open
                rslt = false;

                main_Renamed.Status = "Attempt to open file TAGX.000";

                // attempt to open a 'TAGX.000' file, (if fail update parse_log)
                try
                {
                    file_stream         = new OWFileInputStream(check_owd, "TAGX.0");
                    main_Renamed.Status = "Success file TAGX.000 opened";
                }
                catch (OWFileNotFoundException)
                {
                    file_stream = null;
                    check_pc.attemptCount++;
                    main_Renamed.Status = "Could not open TAGX.000 file";
                }
            }

            // try to parse the file, (if fail update parse_log)
            if (file_stream != null)
            {
                // create the tagParser
                // (this should not be necessary but the parser currently holds state)
                parser = new TAGParser(adapter);

                // attempt to parse it, on success max out the attempt
                if (parseStream(parser, file_stream, owpath, true))
                {
                    xml_parsed            = true;
                    check_pc.attemptCount = ParseContainer.MAX_ATTEMPT;
                }
                else
                {
                    check_pc.attemptCount++;
                }

                // close the file
                try
                {
                    file_stream.close();
                }
                catch (IOException)
                {
                    main_Renamed.Status = "Could not close TAGX.000 file";
                }
            }

            // close the path
            owpath.close();
            main_Renamed.Status = "Path closed";

            // update the main paths listbox if XML file found
            if (xml_parsed)
            {
                // add the paths to the main window
                main_Renamed.clearPathList();
                for (int p = 0; p < paths.Count; p++)
                {
                    main_Renamed.addToPathList(((OWPath)paths[p]).ToString());
                }
            }
        }
        catch (OneWireException e)
        {
            Debug.WriteLine(e);
            main_Renamed.Status = e.ToString();
        }
        finally
        {
            // end exclusive use of adapter
            adapter.endExclusive();
            main_Renamed.Status = "Exclusive 1-Wire aquired released";
        }

        return(rslt);
    }