c# - Kill event thread generated by lambda expression -


I would like to kill the first thread on the second click, then rebuild it. My goal is only a tangent thread in existence.

I believe that I can do such a thread for example with a representative's supply? But I have been roaming for hours without any luck and have slipped it with the hours. Can someone translate my anonymous lambda expression into something with a representative, so that I will recognize and kill my thread after starting it?

I hope my question comes up, I am still learning ... Thanks

  Timer timer 1 = new timer (); Timer 1 Interval = 1000; Timer1.Start (); Private Zero Button 1_Click (Object Sender, EventAgds E) {// If I click on the button twice, how do I kill the first tick thread before creating another? Timer 1 Tick ​​+ = (Sender2, E2) = & gt; Timer1 stopper (sender2, e2, 1, "text"); } Private Zero Timer 1 Volt (Object Sender, EventErgus E, Int Number, String Text) {// Work with Numbers and Text}  

You have created a variable to store only one representative - that is, the action & lt; Object, EventArgS & gt; So something like this:

  Private Action & lt; Object, EventArgues & gt; _handler; Private Zero Button 1_Click (Object Sender, EventArgs e) {if (_handler! = Null) timer1.Tick - = _handler; _handler = (Sender2, E2) = & gt; Timer1 stopper (sender2, e2, 1, "text"); Timer 1 Tic + = _Handler; } Private zero timer 1 volt (object sender, eventAggas E, ent NAM, string text) {timer1.Tick - = _handler; _handler = null; // work with numbers and text}  

Note that this creates the race conditions - "_handler" references to "timer1 dot" thread / em> other Thread sets the context, but earlier adds it to the "tick" event (to avoid running conditions, you want to make a local copy of "_handler".) Hopefully this Gives you an idea ...


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -