Guten Tag,
ich programmiere derzeit ein C# Programm das erstmals rein als Task startet, sprich nur ein Icon in Windows in der Taskleiste angezeigt wird.
Ich habe dort ein Button mit Settings, was ein Fenster öffnet.
Diese Funktion
public static MainFrm configWindow = new MainFrm();
void Settings(object sender, EventArgs e)
{
if (configWindow.Visible)
configWindow.Activate();
else
configWindow.Show();
}
Das Fenster schließe ich dann letztendlich mit
CstmAppContext.configWindow.Dispose();
Scheinbar reicht dies nicht aus und ich erhalte einen Fehlermeldung zu ObjectDispoosedException
System.ObjectDisposedException
HResult=0x80131622
Nachricht = Auf das verworfene Objekt kann nicht zugegriffen werden.
Objektname: "MainFrm".
Quelle = System.Windows.Forms
Stapelüberwachung:
bei System.Windows.Forms.Control.CreateHandle()
bei System.Windows.Forms.Form.CreateHandle()
bei System.Windows.Forms.Control.get_Handle()
bei System.Windows.Forms.Control.SetVisibleCore(Boolean value)
bei System.Windows.Forms.Form.SetVisibleCore(Boolean value)
bei System.Windows.Forms.Control.Show()
bei PwdGenator.CstmAppContext.Settings(Object sender, EventArgs e) in C:\Users\pjhnn\source\repos\PwdGenator\PwdGenator\CstmAppContext.cs: Zeile51
bei System.Windows.Forms.MenuItem.OnClick(EventArgs e)
bei System.Windows.Forms.MenuItem.MenuItemData.Execute()
bei System.Windows.Forms.Command.Invoke()
bei System.Windows.Forms.Command.DispatchID(Int32 id)
bei System.Windows.Forms.NotifyIcon.WndProc(Message& msg)
bei System.Windows.Forms.NotifyIcon.NotifyIconNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(ApplicationContext context)
bei PwdGenator.Program.Main() in
PwdGenator\PwdGenator\Program.cs: Zeile19
Dieser Fehler trifft bei der zeile
configWindow.Show();
auf.
Wo liegt den mein Fehler?
Ich habe die MainFrm configWindow schon auf public static gesetzt um in der Form direkt auf die Variable zuzugreifen, leider hilft das nicht weiter