Jump to content
dkprojektai

Is it Omni question ?

Recommended Posts

Hello, my program in thread is communicating with remote server.

 

In thread....          

            CoInitializeEx(NIL, COINIT_MULTITHREADED);
            try

               some error....


               CoUninitialize;

            except
              on E:Exception do begin

                TThread.Queue(nil,
                procedure
                begin
                   F_Form1.Logging(E.ToString);    //Here I have exception and program throw out....
                end);

                CoUninitialize;
              end;
            end;

 

My question - is it borland or omni problem and how to solve it? I can quote it via try..ecxept, but I really want to log the problem.

 

Edited by dkprojektai

Share this post


Link to post

Even is heap is captured, object life time is not guaranted.

 

i.e. Your Exception object (E) is (certainly) no longer available when Proc in queue is running.

 

Put E.Message in a string just before TThread.Queue

 

Hint :

CoInitialize...

Try

 ...

Finally

  CoUninitialize

end;

would be cooler here !

 

 

Edited by Vincent Gsell
  • Like 1

Share this post


Link to post

Your problem.  Exception objects are not thread safe so accessing them from two different threads when one is about to destroy it anyway is never going to end well.

 

Also it is totally pointless - any threading so writes don't block should be done in the logging library itself not every place that logs something. 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×