`
OOP: Opening threads from a class 2004-03-25 -- Jim Kane Newsgroups: comp.lang.clarion > Now I would really like to do a window that is always on top and shows > me the updated queueentries as they come in. As far as I can see I > need to start this window in it's on thread, but I don't know how and > where do do it in my class definition. > > Can you help me? In any class method right in your code open a dummy window so there is an accept loop and in EVENT:openwindow, start() the window that shows the log. If the data to show is in a queue, then wrap the queue or a ref to the queue in another class and pass the address of the class to the started thread. Here is a quick example. In some cases you may want to use a 2nd local queue on the viewer thread and copy data to it under critical section protection from the global queue that is shared between two threads. If a personal use debug proc I probably would not bother but for something going to a customer I would: mymethod procedure() dummywindow window.... end code if SELF.Viewerthread then message('viewer running already dummy.');return. SELF.ClassToWrapQ&=New ClassToWrapQtype SELF.ClassToWrapQ.init(SELF.Q,SELF.ViewerThread, SELF.CritSecCl) !these 3 lines in the classtowrapq init method: ! SELF.ClassToWrapQ.Q&= parameterQ !Queue with my data to show ! SELF.ClassToWrapQ.ViewerThread&=parameterViewerThread ! SELF.ClassToWrapQ.CSClass&=parameterCritSecClass open(dummywindow) 0{prop:hide}=1 accept case event() of event:openwindow SELF.ViewerThread=start(viewerproc,,address(SELF.ClassToWrapQ)) post(event:closewindow) end end !accept close(dummywindow) kill procedure dummywindow window() end code !try 5000 times to close down the viewer thread if SELF.ViewerThread then loop 5000 times open(dummywindow) 0{prop:hide}=1 accept case event() of event:openwindow Post(event:closewindow,,SELF.ViewerThread,1) post(event:closewindow) end end close(dummywindow) if ~SELF.ViewerThread then break. !self.viewer thread is cleared by the other thread when it closes end !loop end if ~SELF.ClassToWrapQ&=NULL SELF.ClassToWrapQ.Kill() !let the class clean up - dispose crit sec class dispose(SELF.ClassToWrapQ) end Dispose(SELF.Q) !if the viewer thread is not dead you will now get a gpf. Dispose(SELF.CritSecCl) return Jim Kane Printed November 23, 2024, 10:20 pm This article has been viewed/printed 35404 times. Google search has resulted in 8 hits on this article since January 25, 2004. |