簡體   English   中英

Visual Studio 2010 Express-禁用調試事件處理

[英]Visual Studio 2010 Express - Disabling Debug Event Handling

我正在使用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

但是,調試引擎將繼續處理該事件,並且應用程序將繼續緩慢運行。

盡管尚未回答原始問題,但我找到了解決問題的方法。 我的多線程實現不正確。 我沒有為每種異步方法(我的原始實現)在每個框架中創建新線程,而是在應用程序初始化期間創建線程一次,並使用等待句柄(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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM