M
M
Michael2016-04-22 18:57:16
WPF
Michael, 2016-04-22 18:57:16

Is there an implementation of some kind of managed asynchronous thread?

It is necessary to execute the thread asynchronously, in this thread there must be a time delay that needs to be changed. The thread must: run; stop; pause with the option to continue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2016-04-22
@Madfisht3

So start a thread and perform a cyclic operation in it.
1. If you need to complete, check the variable

while (isActiveThread)
{
 // действие
}

2. If you want to stop, enter an Event (eg ManualResetEvent ).
or over time
event.WaitOne(1000); // Ждем сигнального или 1 сек.

D
DarkByte2015, 2016-04-25
@DarkByte2015

If you use TPL, then for example this is possible.

async Task Foo() {}

async Task Foo2()
{
  var task = Foo();
  
  if (await Task.WhenAny(task, Task.Delay(1000)) == task)
  {
    // задача успела выполниться за таймаут
  }
  else
  {
    // задача не успела выполниться за таймаут
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question