简体   繁体   中英

Azure cloud service : System.Threading.Thread not working

I am deploying my web role application on azure cloud. There is a small code block that needs to be executed in separate thread. My code block is as follows:

private static bool Method1()
{
    ...
    ...
    System.Threading.Thread thread = new System.Threading.Thread(() => Method2());
    thread.Start();
    ...
    ...
}

private static void Method2()
{
    ....
    ....
}

I have tested this code in my local system. it is working fine. To check what is happening exactly, I placed code to write in log file. On Azure cloud service Method1() executes without any error. Even code block executed successfully before and after defining and starting thread. but Method2() is never executed.

Is threading not allowed on azure cloud service? Or implementation of threading is different for azure cloud service?

Thank You...

It's very hard to tell from your description. Threading is allowed. One thing to consider is that timing will be different between your machine and the Azure VM.

One possible cause I can think about is process termination before the thread got a chance to be scheduled to run - an exception that kills your application or the main thread exits.

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