简体   繁体   中英

Running a background thread in a custom session state provider

I want to run a background process in a custom session state provider implementation. This would do some custom actions every X minutes for checking the status of the provider. As far as I know: The initialize method of the custom provider should be called once. It is done in the initialization of the custom provider. So I could run my background process there that will be running until the process is recycled in the application pool (and will be running again). So after reading the threads implementation that I can use the background threads seems to be the best option to use.

What do you think about this implementation? Do you see a better way?

Regards,

Finally I have been able to improve the solution that I was wondering in the question.

Run the background thread I want to run in the Initialize method of the class that implements the SessionStateStoreProviderBase:

public sealed class CustomSessionProvider : SessionStateStoreProviderBase
{


    // Initialize the provider
    public override void Initialize(string name, NameValueCollection config)
    {
        try
        {
            Thread t = new Thread(() => MethodName(parameter1, parameter2));
            t.Start();
        }
        catch (Exception e) 
        { 
            //Exception executing the thread

        }
    }

}

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