【问题标题】:Visual Studio 2010 Express - Disabling Debug Event HandlingVisual Studio 2010 Express - 禁用调试事件处理
【发布时间】:2014-06-05 20:37:34
【问题描述】:

我正在使用 Visual C# 2010 Express 来调试 DirectX 应用程序(其中消息循环为每次迭代处理单帧动画)。默认情况下,调试引擎处理“退出线程”(EXIT_THREAD_DEBUG_EVENT) 事件。因为我的应用程序实现了多线程,所以这个事件每帧发生多次(消息循环的迭代)并且事件的处理会减慢我的应用程序的速度。这是不可取的......

有没有一种方法可以禁用单个调试事件处理程序,而无需创建和附加自定义调试引擎?

I know that I can disable the output to the debug window by doing the following:

On the Tools menu, click Options.
In the Options dialog box, select the Debugging node.
Under the expanded Debugging node, select the Output Window entry.

Under General Output Settings on the right hand side of the Options window, change 'Thread Exit Messages' from 'On' to 'Off'

Click OK

但是,调试引擎继续处理事件,应用程序继续缓慢运行...

【问题讨论】:

    标签: c# multithreading visual-studio-2010 debugging


    【解决方案1】:

    虽然最初的问题尚未得到解答,但我已经找到了解决问题的方法。我的多线程实现不正确。我没有为每个异步方法(我的原始实现)在每一帧创建一个新线程,而是在应用程序初始化期间创建线程一次,并使用等待句柄(System.Threading.AutoResetEvent)和“while”循环形式的流控制来重新运行每个异步方法。这是一个示例:

    public static class State
    {
        AutoResetEvent _renderOpsWH,
            _recordWH;
        Thread _recordThread;
        int _ncAsyncOps;
        bool _runThreads;
        ...
    }
    
    public static void Initialize()
    {
        _renderOpsWH = new AutoResetEvent(false);
        _recordWH = new AutoResetEvent(false);
    
        _recordThread = new Thread(Record) { Name = "Recording Device" };
        _recordThread.Start();
    }
    
    public static void Render()
    {
        State._ncAsyncOps = 1;
    
        // signal the 'record' wait handle -- this will allow one execution of the Record method
        State._recordWH.Set();
    
        // 
        // Other work is done here
        //
    
        // wait for all render operations to finish before proceeding
        State._renderOpsWH.WaitOne();
    
        // present scene
    }
    
    public static void Record()
    {
        // State._runThreads is a boolean variable that when false will allow the thread to terminate(simply by exiting the method Record)
        while (State._runThreads)
        {
            // wait for the Render method signal(this controls the execution of this thread)
            State._recordWH.WaitOne();
    
            // record the current frame
            SceneManager.Record(State._pd3dRecorder[State._niRecorder], GetBackBufferSurfaceDesc());
    
            // decrement the count of asynchronous operations. If the count is 0 then signal the wait handle found in the Render method in order to continue with the frame
            if (Interlocked.Decrement(ref State._ncAsyncOps) == 0)
                State._renderOpsWH.Set();
        }
    }
    
    public static void Dispose()
    {
    // set false to break the 'while' loop containing the 'record' thread
    State._runThreads = false;
    
    // signal the 'record' wait handle to allow the final execution of the 'record' thread
    State._recordWH.Set();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多