Fighting Threading?

I am new to C # and I am struggling with Threading (maybe).

When I start debugging and do one at a time, ... and the upload form fills in, the procedure is put in a weird position like this:

    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

      

I suspected this was ok, so I created a new project and executed it. and the result was different than before:

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1()); // Stops here
        }

      

Now I am very confused so I need help. someone told me it is thread-safe, but I have not used threads in my code.

  • PS

    ... I used NAudio library to play music, so I declared in frmMain class like this:

      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();
      (...)
    
          

  • PS

    ... 2 .. And this is the frmMain constructor.

        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);
    
          

+3


source to share


1 answer


It is possible that another piece of code is using multiple threads. I've had situations where there were multiple threads and when I was executing one-step code the current location bounces. This is not a problem if you understand what it does, but if you stop executing in the debugger it can stop something you don't expect.

If you want to stop executing your code, place breakpoints (F9) on the lines of your code, then when you run the operation that is included in your code, follow the step as desired.



If you're wondering how other threads work, there is the Threads window; when debugging go to the Debug window, select Windows, then Themes. If you are not creating your own threads, this can be useful, but it can be useful, but sometimes it is useful to see what might be loaded when the debugger pauses.

-2


source







All Articles