Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

c# - Only one form loads from dll file

I was just hired on with this company to help them make some c# code for a cnc machine they're devving. The part I'm currently working on is to have a plugin run that will run on this software made by a third-party company they got parts of their machine from. The plugin has two windows forms, a primary form that will do most of the things needed for the GUI and a debug form to help test things. They recently had to update the shell used that will run the plugin and now only the debug form will actually load when it runs. In the "PrimaryForm.cs"

public partial class PrimaryForm : Form
{
    //...
    //the debug form is declared here
    DebugForm DebugForm = new DebugForm();
    //...
}

I have a breakpoint here but it's never hit

The only breakpoint that does hit however is in the "DebugForm.cs" file

public partial class DebugForm: Form
{
    public DebugForm()
    {
        //the following method is called in the DebugForm.Desiger.cs file
        InitializeCompnent();
    }
    //...
}

(Keep in mind nobody CS has actually worked on any of this yet, its all been either EE or CE people so zero convention can be seen anywhere) I guessing from this that the dll is for some reason only telling the application running the plugin to load the debugForm. Both form classes are public as well so I'm not sure why the primaryForm isn't being loaded at all. In visual studio the whole project, which inlcudes both form files and everything, is output as a dll so I would think they should be in the same file.

Edit: To explain a little more, the issue isn't even necessarily that the dll is running the DebugForm load_event() first, but that it is running the constructor for the DebugForm first and only that constructor, then it runs the load_event().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When i make a new windows form app it starts off with the main form Program.cs

static void Main()
{
Application.Run(new PrimaryForm());
}

And then I would load additional forms from events. In this case at the same time the primary form loads. Form PrimaryForm

private void PrimaryForm_Load(object sender, EventArgs e)
{
Form DebugForm = new DebugForm();
DebugForm.Show();
}

I did run into a situation where a .bat would load the second form and not the first. It ended up being a bug within the primary form load event that went unnoticed by debugger yet continued on to load second form. It just didn't Show() my primary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...