C# 正在努力解决线程问题?

C# 正在努力解决线程问题?,c#,multithreading,C#,Multithreading,我是C#的新手,我正在努力解决线程问题(也许) 当我开始调试,一个接一个地执行,…并且加载表单完成时,过程被放置在如下奇怪的位置: static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0)

我是C#的新手,我正在努力解决线程问题(也许)

当我开始调试,一个接一个地执行,…并且加载表单完成时,过程被放置在如下奇怪的位置:

    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        if (args.Length > 0)
            Application.Run(new frmMain(args[1]));
        else
            Application.Run(new frmMain());
    } // Stops here
我怀疑这是正常的,所以我创建了一个新项目并执行。结果和以前不一样,像这样:

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1()); // Stops here
        }
  using System;
  using System.Drawing;
  using System.IO;
  using System.Windows.Forms;

  using NAudio;
  using NAudio.Wave;
  using TagLib;
  (...)
  AudioFileReader _audioFileReader;
  IWavePlayer _waveOutDevice = new WaveOut();
  (...)
现在我很困惑,所以我需要帮助。有人告诉我这是线程,但我的代码中没有使用任何线程

  • 另外,我用NAudio图书馆播放音乐,所以我在frmMain课堂上声明如下:

            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1()); // Stops here
            }
    
      using System;
      using System.Drawing;
      using System.IO;
      using System.Windows.Forms;
    
      using NAudio;
      using NAudio.Wave;
      using TagLib;
      (...)
      AudioFileReader _audioFileReader;
      IWavePlayer _waveOutDevice = new WaveOut();
      (...)
    
  • 这是frmMain的构造师

        InitializeComponent();
    
        this.listMusic.DragOver += new DragEventHandler(this.FileDragOver);
        this.listMusic.DragDrop += new DragEventHandler(this.FileDragDrop);
        this.listMusic.DoubleClick += new EventHandler(this.listDoubleClick);
    
        _waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(this.PlaybackStopped);
    
    InitializeComponent();
    this.listMusic.DragOver+=新的DragEventHandler(this.FileDragOver);
    this.listMusic.DragDrop+=新的DragEventHandler(this.FileDragDrop);
    this.listMusic.DoubleClick+=新事件处理程序(this.listdubleclick);
    _waveOutDevice.PlaybackStopped+=新事件处理程序(this.PlaybackStopped);
    

    • 可能是代码的另一部分使用了多线程。我曾经遇到过有多个线程的情况,当我一步一步地遍历代码时,当前位置会跳转。只要您了解它在做什么,它就不是一个真正的问题,但是如果您在调试器中停止执行,它可能会在您不期望的地方停止

      若要停止代码中的执行,请在代码行上放置断点(F9),然后在启动进入代码的操作后,按需要逐步执行


      如果您对其他线程正在运行的情况感到好奇,那么有一个线程窗口;调试时,转到“调试”窗口,选择“窗口”,然后选择“线程”。如果您没有创建自己的线程,它可能有用,也可能不有用,但有时在调试器中暂停执行时,可以方便地查看可能加载的内容。

      请不要链接到外部图像。它严重影响你得到的答案的数量和质量。你能把你问题中的图片内联起来吗?哦,我不知道。很抱歉我现在就编辑。我编辑过,但编辑说我需要10个声誉来附加图像。所以我用代码代替了它。这是一个令人高兴的巧合:代码比代码的图像要好。当你运行应用程序时,是否会关闭它,在主窗体构造函数中也放置一个断点。这不是真的。默认情况下,WinForms将在UI线程(即单个线程)上执行所有操作。