线程池中的DLL绑定从http请求开始

时间:2016-01-14 20:13:48

标签: c# asp.net multithreading oracle dll

我有一个线程池工作项任务,当ASP.net用户在我的网络应用程序中调用特定服务时,该任务开始了。部署环境通过web.config文件中的绑定重定向访问旧版本的Oracle.DataAccess DLL,该文件适用于同步http流量。但是,线程池任务是异步的,并且线程池代码忽略了DLL重定向,并且正在搜索构建它的较新的Oracle DLL。

我尝试在部署它的bin文件夹中删除app.config,[ProjectDLLName] .config和[ProjectDLLName] .exe.config,但它们似乎被忽略了。有没有办法在代码中指定DLL依赖?或者我是否应该使用不同的命名约定来使线程池代码自动在单独的文件中获取运行时标记?

编辑:这是http请求启动线程工作项

的方式
    public class AsynchBuildMugHandler : IHttpAsyncHandler, IReadOnlySessionState
    {
    public bool IsReusable { get { return false; } }

...
    public AsynchBuildMugHandler()
    {
    }
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
...
        AsynchBuildMugOperation asynch = new AsynchBuildMugOperation(cb, context, extraData);

        asynch.StartAsyncWork();
        return asynch;
    }

    public void EndProcessRequest(IAsyncResult result)
    {

        ScenarioCRUD scenDao = new ScenarioCRUD(null);

        if (buildScen != null)
        {
        scenDao.SetJobStatus(buildScen,"IDLE"); // whether cancel/crash/success always set back to idle
        }
    }

    public void ProcessRequest(HttpContext context)
    {
        throw new InvalidOperationException();
    }
    }

    class AsynchBuildMugOperation : IAsyncResult
    {
    private bool _completed;
    private Object _state;
    private AsyncCallback _callback;
    private HttpContext _context;

    bool IAsyncResult.IsCompleted { get { return _completed; } }
    WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
    Object IAsyncResult.AsyncState { get { return _state; } }
    bool IAsyncResult.CompletedSynchronously { get { return false; } }

    public AsynchBuildMugOperation(AsyncCallback callback, HttpContext context, Object state)
    {
        _callback = callback;
        _context = context;
        _state = state;
        _completed = false;
    }

    public void StartAsyncWork()
    {
        ...
        if (validSession)
        {
        if (validScen)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(StartAsyncTask), null);
            _context.Response.Redirect(...ScenarioJobMonitor.aspx"); 
        }
        else
        {
            _context.Response.Redirect(...BuildStartFail.aspx"); // Shortcut to having to pass info around
        }
        }
        else
        {
        _context.Response.Redirect(...login.aspx");
        }
    }

    private void StartAsyncTask(Object workItemState)
    {

        // do a bunch of stuff that invokes Oracle DLL (works synchronously in other parts of the WebApp. 
        // doesn't work here
        _completed = true;
        _callback(this);
    }
    }
}

0 个答案:

没有答案