title: Sleep all threads in program except current/main one in C#
body: <p>Main question is: how to sleep all threads running in program except current/main one?</p>
  
  <p>I have program with use connection to MS SQL Server via EF, the problem is that sometimes when program is running it crush when we put computer to sleep mode and wake up, problem seems to be connection to DB. Program may try to get some data from DB when connection is not yet recovered. Idea was to detect event of <code>PowerModeChanged</code> and when we detect <code>Suspend</code> mode all threads except current should be put into sleep till the next event <code>Resume</code>.
  I do not know how to put to sleep or programmatically hold work of different threads than current one.
  I found this:</p>
  
  <pre><code>ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
  </code></pre>
  
  <p>but I do not find correct way to cast it, or find them by Id, and be able to put them to sleep.</p>
  
  <p>Is there any way to do this?</p>
  
  <p>P.S. Some more code bellow (SystemEvents_PowerModeChanged function, unfinished yet): </p>
  
  <pre><code>[DllImport("Kernel32", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)]
  public static extern Int32 GetCurrentWin32ThreadId();
          private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
          {
              if (e.Mode == PowerModes.Suspend)
              {
                 ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
  
                  int currentThreadId = GetCurrentWin32ThreadId();
                  Console.WriteLine("CURRENT thread: " + currentThreadId);
  
                  foreach (ProcessThread thread in currentThreads)
                  {
                      if (thread.Id != currentThreadId)
                      {
                          Console.WriteLine("Disable thread: " + thread.Id);
                          // Disable threads
                      }
                  }
              }
              else if (e.Mode == PowerModes.Resume)
              {
                  ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
                  int currentThreadId = GetCurrentWin32ThreadId();
                  Console.WriteLine("CURRENT thread: " + currentThreadId);
                  foreach (ProcessThread thread in currentThreads)
                  {
                      if (thread.Id != currentThreadId)
                      {
                          Console.WriteLine("Enable thread: " + thread.Id);
                          // Enable threads
                      }
                  }
              }
          }
  </code></pre>