如何运行方法Backgrounder Worker Class [英] how to run a method Backgrounder Worker Class

查看:80
本文介绍了如何运行方法Backgrounder Worker Class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将此方法放入后台工作程序类,我正在尝试但遇到困难,任何人都可以帮助我如何将此方法运行到后台工作程序类中吗,

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;

推荐答案

请阅读:
http://msdn.microsoft.com/en-us/library/system.componentmodel. backgroundworker.aspx [ ^ ]
Please read this:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]


您并没有真正将函数放入"线程.您可以从线程调用函数(该函数在该线程上执行).使用BackgroundWorker ,您需要从DoWork 事件处理程序中调用它.
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.


在ASP.NET中长时间运行后台线程不是一个好主意,以防出现以下情况:回收.如果我没记错的话,可以在本文中确认:

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

我注意到的另一点是,您在使用控制台做什么是ASP.Net应用程序

Console.WriteLine 吗?
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 ?


这篇关于如何运行方法Backgrounder Worker Class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆