I am writing a Windows Forms application to read and write to my own file type. The program was created using Visual Studio 2015, .NET 4.6.
I had a problem when I was going to associate my program with a file type by right-clicking the file, clicking "Open with", and finally, I checked the ability to always open the file extension with this program. The problem is that when I try to run the program by double-clicking the file , nothing happens. The program does not appear on the screen.
I opened the task manager to find out if it starts, and I noticed that it really starts for a short time, but it works in the background, then it closes.
At first, I thought it was a problem with my project, so I created a new Windows Forms project by changing more than one project parameter and its associated file type, and yet I have the same problem. I also tried the same application on another computer and I have the same problem.
Please note that I really can open the program normally, i.e. double-clicking the .exe file in Windows Explorer, and also launch it through Visual Studio.
This is what I have in Program.cs and Form1.cs in the test project that I created, which also does not start through the association:
Program.cs
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(args.Length == 0 ? new Form1(string.Empty) : new Form1(args[0]));
}
}
Form1.cs
public partial class Form1 : Form
{
public Form1(string path)
{
InitializeComponent();
if (path != string.Empty)
{
MessageBox.Show("File path found!");
}
else
{
MessageBox.Show("No file path found.");
}
}
}
This is new to me because I used to have related file types for my programs, and I had no problems. However, this was with earlier versions of Visual Studio, so I'm not sure if this is due to this.
, , , .
Windows 7 x64, Windows 10 x86.
.