I mentioned to you many times: stop creating threads in the middle of your UI. This way you can spawn any number of threads, one per click. Why?
Create a permanent thread from the very beginning and feed tasks to it. You don't need more then one, right. Hold idle thread with
EventWaitHandle
, for example, or use blocking queue. I recommended it many times, see this:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^]. Alternatively, take a thread from the thread poll, but again, don't do it on every click.
Now
button1_Click
violates all possible Microsoft naming conventions. Don't tell me it generated by Microsoft's designer. Yes, but you're not a robot to repeat it! Use anonymous delegate, grow up.
This is all a foreword, now a word:
You're call
x()
in no-UI thread. It means you should not use UI operation
label2.Text = "mehdi";
. You need to Invoke it. A call to
y()
in your call is valid.
—SA