title: Error: The current thread must be in Single Thread Apartment
body: <p>I have this error whenever i try to open the Openfiledialog : </p>
  
  <blockquote>
    <p>The current thread must be in Single Thread Apartment (STA) mode before OLE calls can be made. Make sure your Main function is marked as STAThreadAttribute. This exception is triggered only if a debugger is attached to the process.</p>
  </blockquote>
  
  <p>My code :</p>
  
  <pre><code>    Dim ofg As New OpenFileDialog
      Dim lvp As New ListViewItem
  
      ofg.Multiselect = True
      ofg.Filter = "All Files|*.*"
      Statue.Text = "Loading..."
  
      If ofg.ShowDialog = Windows.Forms.DialogResult.OK Then
          For Each File As String In ofg.SafeFileNames
  
              Dim hInst As IntPtr = Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0))
              Dim iIcon As Int32 = 0
              Dim hIcon As IntPtr
  
              hIcon = ExtractAssociatedIcon(hInst, File, iIcon)
              ico = Icon.FromHandle(hIcon)
              icondufile = ico.ToBitmap
              Img.Images.Add(icondufile)
              Dim C_File As New IO.FileInfo(File)
  
              Dim ItemFile As ListViewItem = New ListViewItem(C_File.Name)
              lvp = Files_List.Items.Add(ItemFile)
              lvp.SubItems.Add(MD5Checksum(File))
              lvp.SubItems.Add(hash_generator("sha1", File))
              lvp.SubItems.Add(hash_generator("sha256", File))
              lvp.SubItems.Add(GetCRC32(File))
              lvp.SubItems.Add(hash_generator("sha384", File))
              lvp.SubItems.Add(hash_generator("sha512", File))
              lvp.SubItems.Add(C_File.FullName)
              lvp.SubItems.Add(C_File.Extension)
              lvp.StateImageIndex = lvp.Index
  
              ItemFile = Nothing
  
          Next
  
    Private Sub AddFilesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddFilesToolStripMenuItem.Click
      trd = New Threading.Thread(AddressOf AddFiles)
      trd.IsBackground = True
      trd.Start()
      Timer_AddFiles.Start()
  End Sub
  </code></pre>