Home > Net >  C # thread problem
C # thread problem

Time:02-26

C # call a method of c + + library Utils. Search, this method will block the thread within 60 seconds, put the method call thread, how to terminate the thread, not perform after termination of SetResult method
 
Th=new Thread (()=& gt;
{
SetResult (Utils. Search (60));
});
Th. IsBackground=true;
Th. The Start ();
Th. Abort ();//terminate threads


 
CancellationTokenSource CTS=new CancellationTokenSource ();
String res="";
Await Task. Run (()=& gt;
{
The timer. The Start ();
Res=Utils. Search (60);
}, CTS. Token);
if (! CTS. IsCancellationRequested)
{
SetResult (res);
}


Usage scenario is like making sweeping pay (WeChat and pay treasure) code, generate WeChat qr code to tune the query at the same time, during this period and click on the pay treasure to qr code, so you need to query the thread WeChat stop off (to train of thought that is the case, but the thread is not to say stop, don't know how to do,,), have what good solution for
  •  Tags:  
  • C#
  • Related