winforms - Invoke after async call changes two controls -


I can not find a solution to this problem, here is a simple example: on a windows form I have 2 text boxes (InvokeText1, InvokeText2) and two buttons (invokeButton1, invokeButton2). Both button clicks are:

  Private Zero InvokeButton1_Click (Object Sender, EventArgs E) {Form1.GetVersionCompleted + = (Object Sender1, AsyncCompletedEventArgs e1) = & gt; {This.Invoke ((MethodInvoker) (() => {invokeText1.Text = DateTime.Now.ToString ();})); }; Form1.GetVersionAsync (); } Private Zero InvokeButton2_Click (Object Sender, EventArgs e) {Form1.GetVersionCompleted + = (Object Sender1, AsyncCompletedEventArgs e1) = & gt; {This.Invoke ((MethodInvoker) (() => {invokeText2.Text = DateTime.Now.ToString ();})); }; Form1.GetVersionAsync (); }  

Call both async method:

  Public stable event EventHandler & lt; AsyncCompletedEventArgs & gt; GetVersionCompleted; Public Static Zero GetVersionAsync () {ThreadPool.QueueUserWorkItem (o = & gt; {{string result = dateTime.Now.ToString (); GetVersionCompleted (empty, new AsyncCompletedEventArgs (empty, incorrect, result)} GetVersionCompleted (empty, new AsyncCompletedEventArgs (former, false, blank))}}); }  

When a button is clicked, it only updates its corresponding text box when both buttons are clicked, each text box updates both.

I think something should be simple, but I do not know: (

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -