reduce uses of Task.Run

This commit is contained in:
Luke Pulverenti
2013-04-15 15:09:27 -04:00
parent 2b8b98b590
commit b838c53017
5 changed files with 50 additions and 57 deletions

View File

@@ -282,58 +282,54 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return;
}
RaiseReceiveWebRequest(context);
Task.Run(() =>
try
{
RaiseReceiveWebRequest(context);
ProcessRequest(context);
}
catch (InvalidOperationException ex)
{
HandleException(context.Response, ex, 422);
try
{
ProcessRequest(context);
}
catch (InvalidOperationException ex)
{
HandleException(context.Response, ex, 422);
throw;
}
catch (ResourceNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (ResourceNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (FileNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (FileNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (DirectoryNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (DirectoryNotFoundException ex)
{
HandleException(context.Response, ex, 404);
throw;
}
catch (UnauthorizedAccessException ex)
{
HandleException(context.Response, ex, 401);
throw;
}
catch (UnauthorizedAccessException ex)
{
HandleException(context.Response, ex, 401);
throw;
}
catch (ArgumentException ex)
{
HandleException(context.Response, ex, 400);
throw;
}
catch (ArgumentException ex)
{
HandleException(context.Response, ex, 400);
throw;
}
catch (Exception ex)
{
HandleException(context.Response, ex, 500);
throw;
}
catch (Exception ex)
{
HandleException(context.Response, ex, 500);
throw;
}
});
throw;
}
}
/// <summary>

View File

@@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
UpdateLibraryCache(args);
EventHelper.QueueEventIfNotNull(LibraryChanged, this, args, _logger);
EventHelper.FireEventIfNotNull(LibraryChanged, this, args, _logger);
}
#endregion

View File

@@ -195,17 +195,14 @@ namespace MediaBrowser.Server.Implementations.Sqlite
throw new ArgumentNullException("cancellationToken");
}
return Task.Run(() =>
{
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
var cmd = connection.CreateCommand();
cmd.CommandText = "delete from users where guid=@guid";
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
guidParam.Value = user.Id;
var cmd = connection.CreateCommand();
cmd.CommandText = "delete from users where guid=@guid";
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
guidParam.Value = user.Id;
return ExecuteCommand(cmd);
});
return ExecuteCommand(cmd);
}
}
}

View File

@@ -1,11 +1,11 @@
using Alchemy.Classes;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;
namespace MediaBrowser.Server.Implementations.WebSocket
{