void QueueProcessor::ProcessQueues()
	{
		while(!ShouldShutdown())
		{
			auto task = GetTask();
			if (task)
			{
				try
				{
					task->Execute();
				}
				catch(const std::exception&)
				{
					//CurrentException(ex.what());
				}
				catch(...)
				{
				
				}
			}
			else
			{
				WaitForChanges();
			}
		}
	}
sbError
sbiTunesAgentProcessor::ProcessTaskFile()
{
  int retry = 60;

  if (!OpenResultsFile()) {
    return sbError("Failed to open results file to check for start!");
  }
  
  if (OpenResultsFile().tellp() == std::ofstream::pos_type(0)) {
    OpenResultsFile() << '[' << SCHEMA_VERSION << ":2]\n"
                      << '[' << ADDED_MEDIA_ITEMS << "]\n";
  }

  // Keep process all files we find
  while (OpenTaskFile(mInputStream)) {
    if (!mInputStream) {
      // Can't open, maybe it's being written to try again
      if (--retry == 0) {
        return sbError("Unable to open the export track file");
      }
      Sleep(1000);
      continue;
    }
    sbError const & error = Initialize();
    if (error && !ErrorHandler(error)) {
      return error;
    }
    std::string line;
    std::string action;
    std::string source;
    int lineno = 0;
    while (std::getline(mInputStream, line)) {
      std::string::size_type const beginBracket = 
        line.find_first_not_of(" \t");
      // Look for the right bracket as first non-whitespace
      if (beginBracket != std::string::npos && line[beginBracket] == '[') {
        std::string::size_type const endBracket = line.find_last_of(']');
        if (endBracket != std::string::npos) {
          std::string task = line.substr(beginBracket + 1, 
                                         endBracket - beginBracket - 1);
          ParseTask(task, action, source);
          if (action == SCHEMA_VERSION) {
            VersionAction const versionAction = VersionCheck(source);
            action.clear();
            source.clear();
            if (versionAction == ABORT) {
              return sbError("Incompatible version encountered");
            }
            else if (versionAction == RETRY) {
              mInputStream.close();
              continue; // Will hit the inner while and it will stop
            }
          }

          sbError error = ProcessPendingTrackBatch();
          SB_ENSURE_ERRORHANDLER(error);
        }
      }
      else {
        // If there is no action then there's nothing to do yet
        if (action.empty()) {
          ++lineno;
          continue;
        }
        std::string::size_type const equalSign = line.find('=');
        if (equalSign != std::string::npos) {
          std::string const & key =
            Strip(line.substr(0, equalSign));
          std::string const & value =
            Unescape(Strip(line.substr(equalSign + 1)));

          // We've been told to add the track
          if (action == ADDED_MEDIA_ITEMS) {
            sbError const & error = AddTrack(source, key, value, ADDED_MEDIA_ITEMS);
            SB_ENSURE_ERRORHANDLER(error);
          }
          else if (action == UPDATED_MEDIA_ITEMS) {
            sbError const & error = UpdateTrack(key, value);
            SB_ENSURE_ERRORHANDLER(error);
          }
          else if (action == ADDED_PLAYLISTS) {
            sbError error = CreatePlaylist(value);
            SB_ENSURE_ERRORHANDLER(error);
          }
          // We've been told to remove the playlist
          else if (action == DELETED_PLAYLISTS) {
            sbError error = RemovePlaylist(value);
            SB_ENSURE_ERRORHANDLER(error);
          }
          else if (action == UPDATED_SMARTPLAYLIST) {
            sbError const & error = AddTrack(source,
                                             key,
                                             value,
                                             UPDATED_SMARTPLAYLIST);
            SB_ENSURE_ERRORHANDLER(error);
          }
          else {
            std::ostringstream msg;
            msg << action << " is an invalid action , ignoring line " 
                << lineno;
            sbError error(msg.str());
            SB_ENSURE_ERRORHANDLER(error);

            action.clear();
          }
        }
        else {
          // If the line wasn't blank then report an error
          if (!Strip(line).empty()) {
            std::ostringstream msg;
            msg << action 
                << " is an invalid action , ignoring line " << lineno;
            sbError error(msg.str());
            SB_ENSURE_ERRORHANDLER(error);
          }
        }
      }
      ++lineno;
      if (ShouldShutdown()) {
        // Notify shutdown done and exit
        ShutdownDone();
        return sbNoError;
      }
    }
    if (!mTrackBatch.empty()) {
      sbError const & error = ProcessPendingTrackBatch();
      SB_ENSURE_ERRORHANDLER(error);
    }
    // Close the stream and remove the file
    mInputStream.close();
    mInputStream.clear();
    RemoveTaskFile();
  }
  return sbNoError;
}