简体   繁体   中英

Asp.Net MVC Thread was being aborted during long running operation

I have implemented a web application using asp.net MVC to convert excel file into .csv file.

Everything is working fine with small file.

But when I am trying to run larger file I was getting the error at client side "ERR_CONNECTION_RESET".

I have done R & D and have found the solution ie

Even after same I have faced same issue. And then I have implemented threading by referring this Set Timeout For Controller Action .

Now I am getting the exception of "Thread is being aborted".

Here I have added my stack trace. Please help me to sort it out...

Exception: 'Thread was being aborted.' : 
StackTrace: 'at System.Data.Common.UnsafeNativeMethods.IRowset.GetData(IntPtr hRow, IntPtr hAccessor, IntPtr pData)
at System.Data.OleDb.OleDbDataReader.GetRowDataFromHandle()
at System.Data.OleDb.OleDbDataReader.GetValueBinding(MetaData info)
at System.Data.OleDb.OleDbDataReader.GetValues(Object[] values)
at  System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at ExcelToCsvConversion.Controllers.HomeController.Check_In_Masters(String sourceFile, String worksheet2, Int32 colNo, String fieldValue)'

Here Is my code....

   public ActionResult ConvertToCsv(FileUpload model)
    {       
        var fileName = model.SourceFile;
        FileUpload fileUpload = new FileUpload();
        try
        {
            string filename = Path.GetFileName(model.SourceFile);
            model.SourceFile = Path.Combine(Server.MapPath("~/App_Data/uploads"), filename);

                model.WorkSheet1 = "Upload file$";

                System.Threading.Tasks.Task.Factory.StartNew(() => ConvertExcelToCSV_LT(model));

                fileUpload.SourceFile = filename;

        }
        catch (Exception e)
        {
            ServerExceptionLog(e);
        }

        return Json(new { filemodel = fileUpload }, JsonRequestBehavior.AllowGet);
    }

Have you tried playing with

<httpRuntime executionTimeout="HH:MM:SS" />

by default you're limited to 110 seconds.

Increase the upload size in web.config

<system.web>
  <httpRuntime maxRequestLength="2147483647" />
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
    </requestFiltering>
  </security>
</system.webServer>

maxRequestLength is an Int32 ( check here ) so you can set the size accordingly.
maxAllowedContentLength is a uint ( check here )

Did you try it using TaskCreationOptions.LongRunning ?

Task.Factory.StartNew(() => ConvertExcelToCSV_LT(model), 
    TaskCreationOptions.LongRunning);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM