dkprojektai 1 Posted July 12, 2022 (edited) 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 July 12, 2022 by dkprojektai Share this post Link to post
Vincent Gsell 11 Posted July 12, 2022 (edited) 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 July 12, 2022 by Vincent Gsell 1 Share this post Link to post
Brian Evans 105 Posted July 12, 2022 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