SQL CLR awaitable not getting executed

做~自己de王妃 提交于 2019-12-01 13:53:51
Solomon Rutzky

the requirement is for clr to be executed without blocking the main thread

Have you tried without the threading and experienced that it did indeed block the thread? It is possible that you are over-complicating this. Still, some options available are:

  1. Surround the potentially long-running call with Thread.BeginThreadAffinity() and Thread.EndThreadAfinity() as recommended in this comment.

  2. Do multi-threading in what amounts to the "old-fashioned" way by creating a new Thread that handles the long-running call, and wait for it to complete in a loop that calls thread.sleep(x);:

    Thread _RunYouLongTime = new Thread(delegate);
    _RunYouLongTime.Start();
    while (_RunYouLongTime.IsAlive)
    {
      System.Threading.Thread.Sleep(100);
    }
    
  3. If the long-running call is a HttpRequest / Web Service, increase the ServicePointManager.DefaultConnectionLimit Property. This should probably be done regardless of how, or even if, you do threading!

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