Событие срабатывает, когда я отлаживаю, но не когда запускаю его без C# [закрыто]C#

Место общения программистов C#
Ответить
Гость
 Событие срабатывает, когда я отлаживаю, но не когда запускаю его без C# [закрыто]

Сообщение Гость »


I have a ComboBox with the SelectedIndexChanged Event Handler that is firing twice back-to-back while I'm debugging, but when I run it without debugging, it only fires once and it only does this because I trigger it directly. Otherwise, it fires once and not, respectively. Other than the processing waste, I wouldn't mind; however, I don't like having to trigger it manually.

The steps go like this: I have a couple KeyEvents monitoring when I press Shift+Enter. When I do, it adds ComboBox.Text to ComboBox.Items and sets ComboBox.DroppedDown to true.

private void IngredientEnter_KeyPressed(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ShiftKey) ShiftPressed = true; if (e.KeyCode == Keys.Enter) { if (ShiftPressed) { IngredientEnter.Items.Add(IngredientEnter.Text); IngredientEnter.DroppedDown = true; //I manually call the handler because it would call when I would debug, but not when I would just run it. IngredientEnter_SelectedIndexChanged(sender, EventArgs.Empty); } IngredientEnter.Text = ""; e.SuppressKeyPress = true; } } Again, when I'm debugging (if I remove the direct trigger), SelectedIndexChanged fires; when I'm running w/o debugging, it doesn't.

I am using Visual Studio 2022 so if this is the cause, how would I prevent this from happening. I sincerely apologize if this is a dup, but I looked forever and even created an account just to ask.

Edit: I have restructured the question, code, and details for clarity.


Источник: https://stackoverflow.com/questions/780 ... -o-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»