I'm having a FileUploadHandler.ashx in a web service to upload files to server in win forms application.
Even if FileUploadHandler made async / sync (tried both), it's taking time for every 5th Request...
I've a large no.of files, looping them to upload and for every consecutive 5th Request takes so much time....
I've created a log file to check which request is taking time as it follows below:
Request 1; Time Taken: 0.0717544
Request 2; Time Taken: 0.019239
Request 3; Time Taken: 0.0297877
Request 4; Time Taken: 0.0041714
Request 5; Time Taken: 99.9442763
Request 6; Time Taken: 0.031179
Request 7; Time Taken: 0.0332562
Request 8; Time Taken: 0.0037856
Request 9; Time Taken: 0.0283765
Request 10; Time Taken: 99.9690294
My FileUploadHandler.ashx code as follows:
/// <summary>
/// Summary description for FileUploadHandler
/// </summary>
public class FileUploadHandler : IHttpAsyncHandler
{
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
AsynchOperation asynch = new AsynchOperation(cb, context, extraData);
asynch.StartAsyncWork();
return asynch;
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
}
public bool IsReusable
{
get
{
return false;
}
}
}
class AsynchOperation : IAsyncResult
{
private bool _completed;
private Object _state;
private AsyncCallback _callback;
private HttpContext _context;
private GCloudUploadingModel gclouduploadingdatamodel;
bool IAsyncResult.IsCompleted { get { return _completed; } }
WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
Object IAsyncResult.AsyncState { get { return _state; } }
bool IAsyncResult.CompletedSynchronously { get { return false; } }
public AsynchOperation(AsyncCallback callback, HttpContext context, Object state)
{
_callback = callback;
_context = context;
_state = state;
_completed = false;
}
public void StartAsyncWork()
{
try
{
ThreadPool.QueueUserWorkItem(new WaitCallback(StartAsyncTask), null);
}
catch (Exception ex)
{
// SEND ERROR MAIL TO TECHNICAL TEAM
using (CommonBussinessAccess ErrorSending = new CommonBussinessAccess())
{
ErrorSending.SendFailureInfoEmailToTechnicalTeam(new PracticeModel(), this.GetType().Name, "StartAsyncWork", ex.Message, ex, new EMRWebExceptionTraceLogModel());
}
}
finally
{
_completed = true;
_callback(this);
}
}
private void StartAsyncTask(Object workItemState)
{
try
{
//Uploading code....
}
finally
{
}
}
Please Help...