visual studio(2015/2017)调试多线程程序

您所在的位置:网站首页 线程在哪里看 visual studio(2015/2017)调试多线程程序

visual studio(2015/2017)调试多线程程序

2023-09-18 06:18| 来源: 网络整理| 查看: 265

教程来自巨头微软官方机翻 动手完成全部内容大约需要半小时 完成整个教程的效果图:(本人使用vs2015 & C++)

正文:

开始调试多线程应用程序 (C#,Visual Basic、 c + +)

Visual Studio 提供多种工具和用户界面元素,用于调试多线程应用程序。 本教程演示如何使用线程标记、“并行堆栈”窗口、“并行监视”窗口、条件断点、筛选器断点。 完成本教程只需数分钟,然后你就会熟悉用于调试多线程应用程序的功能。

下面两个主题额外介绍了如何使用其他多线程调试工具:

若要使用“调试位置”工具栏和“线程”窗口,请参阅演练:调试多线程应用程序。

如需使用 Task(托管代码)和并发运行时 (C++) 的示例,请参阅演练:调试并行应用程序。 有关适用于大多数多线程应用程序类型的常规调试技巧,请阅读该主题和本主题。

首先需要一个多线程应用程序项目。 示例如下。

创建一个多线程应用项目

在“文件”菜单上,选择“新建” > “项目”。

此时将出现“新建项目”对话框。

选择语言:Visual C#、Visual C++ 或 Visual Basic。

在“Windows 桌面”下,选择“控制台应用”。

在“名称”字段中,输入 MyThreadWalkthroughApp。

选择“确定”。

新的控制台项目随即显示。 创建该项目后,将显示源文件。 根据所选语言,源文件名称可能是 Program.cs、MyThreadWalkthroughApp.cpp 或 Module1.vb。

删除出现在源文件中的代码,将其替换为下面列出的相应示例代码。

C#

using System; using System.Threading; public class ServerClass { static int count = 0; // The method that will be called when the thread is started. public void InstanceMethod() { Console.WriteLine( "ServerClass.InstanceMethod is running on another thread."); int data = count++; // Pause for a moment to provide a delay to make // threads more apparent. Thread.Sleep(3000); Console.WriteLine( "The instance method called by the worker thread has ended."); } } public class Simple { public static void Main() { for (int i = 0; i < 10; i++) { CreateThreads(); } } public static void CreateThreads() { ServerClass serverObject = new ServerClass(); Thread InstanceCaller = new Thread(new ThreadStart(serverObject.InstanceMethod)); // Start the thread. InstanceCaller.Start(); Console.WriteLine("The Main() thread calls this after " + "starting the new InstanceCaller thread."); } }

C++

#include "pch.h" #include #include #include int count = 0; void doSomeWork() { std::cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3