Фон
Я переключил операционные системы, и мое приложение на C # формах, которое работало нормально, не работает должным образом.Я использовал Visual Studio 2017 для Windows и сейчас использую последний выпуск MonoDevelop в Ubuntu.
Issue
У меня есть основная форма, вторая форма итретья форма, которая открывается в таком порядке по запросу пользователя.Третье окно просто отображает график, без интерактивных кнопок, кроме изменения размера / закрытия.
После запуска третьего окна его метод BeginInit()
вызывает метод главной формы Dispose(bool)
, а затем закрывает главное окно, затем второе окно, и приложение зависает до тех пор, пока я не остановлю отладку из графического интерфейса разработчика.Кажется, я не могу найти ничего, что указывало бы на то, почему это происходит, хотя я очень плохо знаком с MonoDevelop, поэтому, возможно, я не смотрю в правильные места.
Код
Основная форма:
// Open Second Window called "Diagnostics"
private void Plots_Click(object sender, EventArgs e)
{
Application.Run(new Diagnostics(xmlDirectory));
}
Вторая форма «Диагностика»:
// Set up stuff and run the Third window called "ChartDisplay"
private void GenerateChart_Click(object sender, EventArgs e)
{
// irrelevant code
Application.Run(new ChartDisplay(datapoints, horizontalChoice, verticalChoice));
}
Третья форма «ChartDisplay»:
public ChartDisplay(List<object[]> data, string xAxisLabel, string yAxisLabel)
{
InitializeComponent();
// irrelevant code that doesn't get run
}
ChartDisplay.Designer:
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); // last line to get called
// ...
}
Отладка
При входе в вызов ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
в Chart.Designer.cs
InitializeComponent()
происходит прямой переход к методу Dispose(bool)
основной формы, как я упоминал ранее.Переходя ко всему оттуда просто циклически перебирайте функцию Dispose, пока не закроется главное окно, а затем все другие окна закроются, и приложение останется зависшим.
Я поместил стек вызовов в Dispose(bool)
внизу этого поста, потому чтоэто долго.
То, что я пробовал
Единственная помощь, которую я смог найти в отношении подобных проблем, предлагает использовать Application.Run(Form)
вместо создания новогоForm
объект и вызов его Show()
метода.Как показано выше, я перешел на этот метод и до сих пор без игры в кости.
Я попытался добавить метод для предотвращения закрытия окон:
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
this.Hide();
e.Cancel = true;
}
Но это ничего не делает, даже не вызывается.
Пройдя через все, на самом деле ничего не получается.Кажется, я не могу войти в функции, которые вызывают проблемы, такие как BeginIinit()
Стек вызовов на Dispose(bool)
BitClean.MainWindow.Dispose(bool disposing) in /home/me/myapp/MainWindow.Designer.cs:15
System.ComponentModel.Component.Dispose() in
System.Windows.Forms.Form.WmClose(System.Windows.Forms.Message m) in
System.Windows.Forms.Form.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.Control.ControlWindowTarget.OnMessage(System.Windows.Forms.Message m) in
System.Windows.Forms.Control.ControlNativeWindow.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.NativeWindow.WndProc(System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) in
System.Windows.Forms.XplatUIX11.SendMessage(System.IntPtr hwnd, System.Windows.Forms.Msg message, System.IntPtr wParam, System.IntPtr lParam) in
System.Windows.Forms.XplatUI.SendMessage(System.IntPtr handle, System.Windows.Forms.Msg message, System.IntPtr wParam, System.IntPtr lParam) in
System.Windows.Forms.Form.Close() in
System.Windows.Forms.Application.Exit(System.ComponentModel.CancelEventArgs e) in
System.Windows.Forms.Application.Exit() in
System.Windows.Forms.Application.OnThreadException(System.NotImplementedException t) in
System.Windows.Forms.NativeWindow.OnThreadException(System.NotImplementedException e) in
System.Windows.Forms.NativeWindow.WndProc(System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) in
System.Windows.Forms.XplatUIX11.DispatchMessage(System.Windows.Forms.MSG msg) in
System.Windows.Forms.XplatUI.DispatchMessage(System.Windows.Forms.MSG msg) in
System.Windows.Forms.Application.RunLoop(bool Modal, System.Windows.Forms.ApplicationContext context) in
System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) in
System.Windows.Forms.Application.Run(BitClean.Diagnostics mainForm) in
BitClean.MainWindow.Plots_Click(System.Windows.Forms.ToolStripMenuItem sender, System.Windows.Forms.MouseEventArgs e) in /home/me/myapp/MainWindow.cs:254
System.Windows.Forms.ToolStripItem.OnClick(System.Windows.Forms.MouseEventArgs e) in
System.Windows.Forms.ToolStripMenuItem.OnClick(System.Windows.Forms.MouseEventArgs e) in
System.Windows.Forms.ToolStripMenuItem.HandleClick(int mouse_clicks, System.Windows.Forms.MouseEventArgs e) in
System.Windows.Forms.ToolStripItem.FireEvent(System.Windows.Forms.MouseEventArgs e, System.Windows.Forms.ToolStripItemEventType met) in
System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) in
System.Windows.Forms.ToolStripDropDown.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) in
System.Windows.Forms.Control.WmLButtonUp(System.Windows.Forms.Message m) in
System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.ToolStrip.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.ToolStripDropDown.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.Control.ControlWindowTarget.OnMessage(System.Windows.Forms.Message m) in
System.Windows.Forms.Control.ControlNativeWindow.WndProc(System.Windows.Forms.Message m) in
System.Windows.Forms.NativeWindow.WndProc(System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) in
System.Windows.Forms.XplatUIX11.DispatchMessage(System.Windows.Forms.MSG msg) in
System.Windows.Forms.XplatUI.DispatchMessage(System.Windows.Forms.MSG msg) in
System.Windows.Forms.Application.RunLoop(bool Modal, System.Windows.Forms.ApplicationContext context) in
System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) in
System.Windows.Forms.Application.Run(BitClean.MainWindow mainForm) in
BitClean.Program.Main() in /home/me/myapp/Program.cs:19