Home > Net > How to wait for a method execution after the success of the callback to the back of the code
How to wait for a method execution after the success of the callback to the back of the code
Time:11-05
I have a thread, you need to call a message is sent, the news if you don't send success will continue to the next message will appear to repeat several situation, sending a message function I added the Action parameter, if after sending a message no matter whether success will callback the Action, so that the outside can see inside the message has been sent you won't get duplicate messages, but I don't know how to perform outside Such as sending a message is: Instance. SendMsg (string MSG, string userid, Action Success=null); I am now outside direct call for(int i=0; i<10; I++) { The Instance. The sendMsg (" hello ", 10086); } How to write this kind of circumstance can according to the action to do the next Instance. The sendMsg? The queue? Queue also can't determine whether to send a success?
CodePudding user response:
With a Task to perform and Task where waiting, performed to give the mainline cenfa notice, for example,
Task t=new Task (()=& gt; {the Instance. The sendMsg (" hello ", 10086); }); T.S tart (); T.W ait (); This. The Dispatcher. Invoke (()=& gt; {MessageBox. Show (" do next "); });