Question:
I am using the Chilkat Socket asynchronous methods. To implement a progress Bar I tried using the event callback functions (in C++).
socket.put_EventCallbackObject(&myProgressObj); socket.put_HeartbeatMs(200);where myProgressObj is an instance of a class derived from CkBaseProgress. I am calling the AsyncReceiveBytesN method to read an amount of binary data, but no callback methods are being called. What's wrong?
There are no event callbacks for asynchronous methods. The definition of an event callback has to do with a single thread of execution. The thread of execution proceeds like this:
When an asynchronous method is called, Chilkat creates a background thread to run the task. The method that initiates the async task returns immediately to your application (in this case, AsyncReceiveBytesN returns and a separate background thread is doing the ReceiveBytesN). There cannot be a callback from the background thread to your app's foreground thread, because they are separate threads of execution. (Technically it's possible, but all sorts of problems can arise depending on the application's architecture, programming language, etc. where app code in a background thread is restricted especially when it comes to accessing UI elements.) The foreground thread of your application can choose to periodically check the current status of a background (async) task by examining whatever properties might be available for such a thing: such as by examining the socket.ReceivedCount property.