Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to put this method into background worker class, I am trying but stuck, can any one help me how to run this method into background worker class,

public string Zip(string f, bool original) {
string zip = "";
try
{
    files = HttpContext.Current.Server.UrlDecode(files);
    string[] fileCollection = files.Split('*');
    zipFile = class1.zipfile(fileCollection, IsOriginal);

    int fileLength = files.Length;
}
catch (Exception ex)
{
    Console.WriteLine("Exception during processing {0}", ex);

}
return File;
Posted
Updated 7-Feb-11 23:22pm
v3

 
Share this answer
 
You don't really "put" a function into a thread. You can call a function from a thread (and the function executes on that thread). With the BackgroundWorker you'd need to call this from the DoWork event handler.
 
Share this answer
 
Comments
bachasafyan 9-Feb-11 4:05am    
so how can i do it?
Nish Nishant 9-Feb-11 8:52am    
Just add a call to your Zip method in the DoWork event handler.
It is not good idea to have long running background threads in ASP.NET in case of recycling. If I remember correctly, this can be confirmed in this article:

http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/

Another point which I noticed, what are you doing with console is ASP.Net Application

Console.WriteLine ?
 
Share this answer
 
Comments
Nish Nishant 8-Feb-11 11:42am    
Technically, you can use HttpContext outside of an ASP.NET application (if you wanted to).
Manas Bhardwaj 8-Feb-11 11:52am    
Agree!
fjdiewornncalwe 8-Feb-11 12:00pm    
I agree in principle, but I have executed long running processes that don't need to provide response back to the front end application by pulling the values form the HttpContext and copying them to a "safe" object that then gets passed to the thread for processing.
bachasafyan 9-Feb-11 4:05am    
Marcus Kramer: It is zipping utitlity to zip large size zip files:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900