are the http request/response of casablanca multithreaded in a COM STA object ?i.e do the task of casablanca run parallel in a COM STA object ?

Nov 3, 2015 at 8:27 AM
Edited Nov 3, 2015 at 10:21 AM
Hi,
I make http request/response (and upload of file too ) with casablanca in a COM STA object. (an outlook addin)
it seems to block the software ( I cannot do something else and must wait).

the following code is in a send(...) function in my STA COM object:
client.request(requete).then([this](task<http_response> responseTask)
                {
                    http_response response;

                    try
                    {
                        
                        response = responseTask.get();
                    }
                    catch (const http_exception &e)
                    ...
does casablanca run well and parallel in a COM STA object ? shall I do something more to run my tasks parallel ?

or should I use atlserver library(or winhttp) and win32 instead of casablanca for http requests and multithreading(win32) in my COM object ?
(I will still use casablanca to parse the json in the responses.)
Nov 4, 2015 at 1:26 AM
The scenario you mention should work without freezing the UI.
Ideally, PPL posts the continuation on a worker thread (not the UI thread). And it is upto the application developer to handle this and post the required data back to the UI thread.
So I am not sure why you are seeing a hang in the UI.

thanks
Kavya.
Nov 4, 2015 at 8:24 AM
Edited Nov 4, 2015 at 8:39 AM
does it freeze because I am using wait() after each .then ?
client.request(requete).then([this](task<http_response> responseTask)
                {
                    http_response response;

                    try
                    {
                        
                        response = responseTask.get();
                    }
                    catch (const http_exception &e)
                    ...
                 }.wait();

another problem is that to post data to the UI thread I must do unmarshalling of my COM object in the secondary thread and I must transmit a stream or a pointer on a stream to do that as parameter of the lambda and thecasablanca rest sdk doesn't transmit well the pointer on the stream as parameter of the lambda function (it doesn't work well ,with casablanca there are some things that we cannot transmit well as parameter of the lambdas)....(I have already tried to transmit a stream to the lambda (to the secondary thread) and it doesn't work.)
Nov 6, 2015 at 11:49 AM
Hi,
I have tried again to unmarshall in the progress handler of casablanca, I get the stream now, but it is blocked on CoUnmarshalInterface.....and if I don't use unmarshalling and call posthreadmessage it seems that the message don't arrive in the ui thread (in my progress bar control)...
Nov 6, 2015 at 2:29 PM
I dont know if casablanca is suitable for use in a STA COM objet ?
Nov 6, 2015 at 8:27 PM
Calling task::wait() or task::get() from a UI thread will block the thread and cause it to be unresponsive.

Casablanca can be used from STA COM objects, we have customers using Casablanca in MFC applications (from the MFC UI).
Casablanca has no knowledge that it is operating from a STA COM object, so if you need to add any UI update functionality, it would be similar to how you would do it from any worker thread.

This discussion has some details about how to use Casablanca in a MFC application, it might have some pointers for your scenario: http://casablanca.codeplex.com/discussions/540198

Thanks
Kavya
Nov 9, 2015 at 8:20 AM
Hi kavyako,

I dont use MFC, but I use ATL(active template library) because it is a COM object in an outlook addin.
Nov 9, 2015 at 8:26 AM
I cannot communicate with the UI thread from the progress handler of casablanca
I will try too without the wait() but I don't know if it will work
Nov 9, 2015 at 9:37 AM
Hi
My problem for the wait() is the following : I have a first function that do : in a loop it reads several files and upload them and when I have received a response for each file uploaded Iadd it to a list and when I have recived all the response , I have a second function that send another http request that contains the response for each file of the first function, so I must wait in the first function that I have received all the response for each file and that each file is uploaded that ès why I use wait(). I would like to do without the external wait() (of the ui thread) but I don't know how to do because I have a loop and i must wait that all the file are uploaded and that I received each response for each file....
Nov 9, 2015 at 4:16 PM
Hi,
I have tried something without the external wait() (on the ui thread) but my project doesn't work anymore.....so I go back with my external wait().
Jan 8, 2016 at 1:34 PM
Hi kavyako,
I have solved my multitasking problem in casablanca in a COM STA object with ATL.I have removed the external wait and made other modifications, and I have used windows message and postmessage to signify the end of the secondary task to a windows of the main thread of my COM STA object....
so my problem is now solved....
Marked as answer by stephane_l2 on 1/8/2016 at 5:34 AM