C# STAThread error (SaveFileDialog) on a new Form
So basicaly i have made a login system for my program, and when a user
logs it it opens up Form1. But i need the Form1 to be a STA thread. I am
getting this error in Form1:
{"Current thread must be set to single thread apartment (STA) mode before
OLE calls can be made. Ensure that your Main function has
STAThreadAttribute marked on it. This exception is only raised if a
debugger is attached to the process."} In this code
SaveFileDialog FSave = new SaveFileDialog()
{
Filter = "Executable Files|*.exe",
InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
};
if (FSave.ShowDialog() == DialogResult.OK)
this is my Program.cs
using System;
using System.Windows.Forms;
namespace hwid_login_system
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
}
No comments:
Post a Comment