Ejemplo n.º 1
0
 private void EnqueueMediaFileSearch(SearchThreadParameters parameters)
 {
     lock (mMediaFileSearchQueue)
     {
         mMediaFileSearchQueue.Enqueue(parameters);
     }
     mMediaFileSearchTrigger.Set();
 }
Ejemplo n.º 2
0
		private void SearchWorker(object state)
		{
			SearchThreadParameters parameters = (SearchThreadParameters)state;
			
			//Flag to indicate that the search thread should abort without raising completion events
			bool abortThreadWithoutCompletion = false;

			//If there is an existing search thread, terminate it
			TerminateSearch();
			//Become the new search thread
			mSearchThread = Thread.CurrentThread;
			//This can now be terminated itself, so catch abort exceptions
			try
			{
				SettingsChanged = false; //Clear search settings changed (flag is to indicate change since search started)

				parameters.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(delegate
				{
					Results.Clear();
					IsSearching = true;
				}));

				SearchInternal(parameters.Artist, parameters.Album, new ScriptResults(this, parameters.Dispatcher));
			}
			catch (ThreadAbortException e)
			{
				abortThreadWithoutCompletion = (e.ExceptionState as bool?).GetValueOrDefault();
			}
			finally
			{
				if (abortThreadWithoutCompletion)
				{
					//Don't use property setter, as no events should be raised.
					mIsSearching = false;
				}
				else
				{
					//Signal completion, at high priority, as this will hold up thread tear-down if it has to wait.
					parameters.Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate
					{
						IsSearching = false;
						RaiseSearchCompleted();
					}));
				}
			}
		}