简体   繁体   English

Azure云服务:System.Threading.Thread无法正常工作

[英]Azure cloud service : System.Threading.Thread not working

I am deploying my web role application on azure cloud. 我正在将Web角色应用程序部署在Azure云上。 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. 在Azure云服务上,Method1()的执行没有任何错误。 Even code block executed successfully before and after defining and starting thread. 甚至在定义和启动线程之前和之后都成功执行了代码块。 but Method2() is never executed. 但是永远不会执行Method2()。

Is threading not allowed on azure cloud service? Azure云服务上不允许使用线程吗? Or implementation of threading is different for azure cloud service? 还是Azure云服务的线程实现不同?

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. 要考虑的一件事是,计算机和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. 我可能想到的一个可能原因是在线程有机会运行之前终止了进程-导致应用程序终止或主线程退出的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM