Prevent IIS from killing a Task before it ends - Part 2

偶尔善良 提交于 2019-12-13 02:07:15

问题


This is a continuation of

Prevent IIS from killing a Task before it ends

My question:

Given

public static Task StartNew(Action act)
{
    IISNotifier notif = new IISNotifier(); -> HostingEnvironment.RegisterObject(this);
    notif.Started();
    return Task.Factory.StartNew(() => {
        act.Invoke();
        notif.Finished(); ->  HostingEnvironment.UnregisterObject(this);
    });
}

Invoked by

    return new LogResult(id, IISTaskFactory.StartNew(() => 
        DoLogInAzure(account, id, exception, request))
    );

Example implementation

    DoLogInAzure(account, id, exception, request)) {

            DoSomeLongOperation()
            **Thread.Yield()**
             DoLogInAzure();

    }

The above is just example code. To illustrate Thread.Yield statement Ive made it recursive.

Question Please bear in mind this is running in a Azure web role or potentially an Azure website. 1.) What does the Thread.Yield() statement actually do in the context of IIS in the above example? 1a.) I would assume it would allow the thread to service other incoming requests 1b.) Would it allow IIS to tear down the thread i.e. would the recursion stop?

Many thanks, especially to Gervasio Marchand, Damian Schenkelman and that blog post of Phil Haack and to you too if you can answer it :)

来源:https://stackoverflow.com/questions/21583232/prevent-iis-from-killing-a-task-before-it-ends-part-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!