.net - Best way to connect multiple event handlers to one event in C#? -



.net - Best way to connect multiple event handlers to one event in C#? -

i'm writing simple encryptor program. when type in first textbox encrypted text appears on sec textbox on fly using textchanged event. have button load key files. problem if type first in textbox , load keyfile afterwards encrypting handler not called, because it's hooked textchanged event, , have write first textbox invoke it.

to solve hooked 2 events load button's click event, 1 loading key file, , other same hooked textchanged event. (i avoid code duplication.)

this working correctly, how can sure, everytime key file loading happens , finishes before encrypting function called? there improve way this?

you should consider creating separate methods:

private list<string> keycodes; private void loadkeycodesbutton_click(object sender, routedeventargs e) { loadkeycodes(); updateoutput(); } private void inputtextbox_textchanged(object sender, textchangedeventargs e) { updateoutput(); } private void loadkeycodes() { // load key codes here keycodes = new list<string>(); // etc. } private void updateoutput() { outputtextbox.text = encrypttext(inputtextbox.text); } private string encrypttext(string input) { // utilize keycodes encrypt homecoming input; }

the encryption placed within separate class, help started.

c# .net events handlers

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -