Archived Forum Post

Index of archived forum posts

Question:

Chilkat.Task OnTaskCompleted not raised

Dec 30 '15 at 08:05

Hi, (C#, .Net 4.5.2, Chilkat 9.5.0.55, Ftp2, Ftp2.ConnectAsync())

I'm trying to use the OnTaskCompleted-Event on the Ftp2 class. The Synchronous method (Connect()) works perfectly. Also the async method when using task.Wait(0). But I'd like to us ethe OnTaskCompleted-Event to don't block my thread. My code snippet:

        var tcs = new TaskCompletionSource<bool>();
        var t1 = ftp.ConnectAsync();
        t1.OnTaskCompleted += (sender, args) => {
            var t2 = args.Task;
            tcs.SetResult(t2.GetResultBool());
        };

        if (!t1.Run()) {
            tcs.SetResult(false);
        }
        return tcs.Task;

But my Task never finishes because OnTaskCompleted is not invoked.

Thanks in advance


Accepted Answer

I know this is confusing, but the event is actually on the ftp object, not the Task object.

ftp.OnTaskCompleted += ....