콜백 메서드를 호출 할 때까지 기다렸다가 그 후에 작업을 계속하고 싶습니다. 나는 다음과 같이 시도했다 :비동기 메서드 호출을 기다리는 중
ThreadPool.QueueUserWorkItem(_ =>
{
DoWOrk(callbackmethod, inputstring);
ctx.Post(state => { }.null);
그러나 callback은 DO 작업을 수행 한 후에 시작되지 않았다.
콜백 메서드를 호출 할 때까지 기다렸다가 그 후에 작업을 계속하고 싶습니다. 나는 다음과 같이 시도했다 :비동기 메서드 호출을 기다리는 중
ThreadPool.QueueUserWorkItem(_ =>
{
DoWOrk(callbackmethod, inputstring);
ctx.Post(state => { }.null);
그러나 callback은 DO 작업을 수행 한 후에 시작되지 않았다.
var tcs = new TaskCompletionSource<object>();
DoWork(() => { //wrap callback
callbackmethod(); //call original callback
tcs.SetResult(null); //signal task
}, inputstring);
var task = tcs.Task; //await this task or use ContinueWith
DoWork 메소드가 범위를 벗어나는 것처럼 들립니다. –