c# - Using a Button Tag -


Program logic changes a button tag based on random things - but using the UI thread.

Is the button tag value reliable to use in a click event? That is, will it be the same value as the event occurs at the handler, because it was at the time of the click?

If not, what is the best way to pass an event specific parameter on the button, click on the event that will be safe?

Update

An example was added as a request. (Remember this is just theoretical).

  windows.form. Timer timer = new timer (); Timer Interval = 1; Timer Tick ​​+ = new event handler (timer_tick); Timer.start (); Zero timer_tick (object sender, event events e) {this.button.Tag = Random.NextInt (100). Ostring (); } Zero button_click (object sender, eventArgse E) {string s = (string) ((button) sender) .tag; Console. Light line ("tag value as push button:" + s); } Enter another way, the question has emerged: Events can be covered in the GUI event queue which pushed the position of the button and allows to change between the click event. Assume pushing?   

Assume that you are using winforms

IMHO you Tags can control the property to pass specific criteria, but you should also remember that the Windows Forms control threads are not safe to make a thread-safe call, you InvokeRequired Should use the following links to set the text in a thread-safe way for the textbox Gives an example but for the tag property it should not be very different.

Hope it helps.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -