@Quark_Hell
C++ программист

Почему в winforms иногда выкидывает indexOutOfRange ошибку при срабатывании Application.Exit()?

Здравствуйте. Решил убрать стандартные кнопки управления формой(закрыть, расширить) и сделать свои. Для кнопки закрывания написал вот такой не сложный код:
private void GunaCloseButton_Click(object sender, EventArgs e)
{
     Application.Exit();
}


Однако, иногда, при закрытии приложения выскакивает IndexOutOfRange ошибка, происходящая где-то внутри. Вот стек трейс ошибки:
System.IndexOutOfRangeException
  HResult=0x80131508
  Message=Index was outside the bounds of the array.
  Source=mscorlib
  StackTrace:
   at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
   at System.Array.SetValue(Object value, Int32 index)
   at System.Collections.Hashtable.CopyValues(Array array, Int32 arrayIndex)
   at System.Collections.Hashtable.ValueCollection.CopyTo(Array array, Int32 arrayIndex)
   at System.Windows.Forms.Application.ThreadContext.ExitCommon(Boolean disposing)
   at System.Windows.Forms.Application.ExitInternal()
   at System.Windows.Forms.Application.Exit(CancelEventArgs e)
   at System.Windows.Forms.Application.Exit()
   at ManualC_.Form1.GunaCloseButton_Click(Object sender, EventArgs e) in E:\Manual\ManualC#\ManualC#\Form1.cs:line 219
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at ManualC_.Program.Main() in E:\Manual\ManualC#\ManualC#\Program.cs:line 19


Кто-то сталкивался с такой проблемой, как её можно решить?
  • Вопрос задан
  • 58 просмотров
Решения вопроса 1
Adler_lug
@Adler_lug
А если Environment.Exit(0) ?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы