0

I have a void Function and I need to return a FileResult or call a FileResult action from this void function. Is there any way that this can be done?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • you mean you want to return FileResult from a void function? – Jitendra Pancholi Sep 17 '14 at 13:57
  • yes. that is exactly my aim. this may sound funny but since I called that void function from a Task.Factory.StartNew() and I need a FileResult as the final output of the task. – user3579974 Sep 17 '14 at 14:16
  • As per my understanding, you want to download the file using above? – Jitendra Pancholi Sep 18 '14 at 05:19
  • yes, i'm trying to find a way that I can use FileResult as a background process. Is there anyway this is possible? One of my plan is to call an asynchronous void task and return a FileResult. – user3579974 Sep 19 '14 at 12:34
  • async call to return a FileResult would not let you to download the file. What would happen if you leave the page before completion of file download request? – Jitendra Pancholi Sep 19 '14 at 13:06
  • I tried that once but it is not yet implemented asynchronously, the system will just wait to finish the download before you can proceed to other actions. Is there any possible way that I can have an async file download? – user3579974 Sep 19 '14 at 13:34

1 Answers1

0

I had devised a workaround, so that the output of my void function is monitored even running asynchronously. I created a javascript window.setInterval function that checks every now and then if the void function has created the final output file which is a zipfile. To monitor this, I used a cookie that has the filename of the zipfile. Once the file is readable, that is the time when I will send the filename to be in a FileResult function.

var exportPhotoBatchck
    exportPhotoBatchck = window.setInterval(function () {
        var exportcookieValue = $.cookie('ExportBatchToken');

        function() 
        {  
             //Function that checks whether the cookievalue is a valid file.
        }

    }, 1000);