A class that implements a Single Threaded Apartment. Users will subclass this and override OnInit() and OnQuit() where they will create and destroy a COM component that wants to run in an STA other than the main STA.
| 25 | * component that wants to run in an STA other than the main STA. |
| 26 | */ |
| 27 | public class STA extends Thread { |
| 28 | /** |
| 29 | * referenced by STA.cpp |
| 30 | */ |
| 31 | public int threadID; |
| 32 | |
| 33 | /** |
| 34 | * constructor for STA |
| 35 | */ |
| 36 | public STA() { |
| 37 | start(); // start the thread |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * (non-Javadoc) |
| 42 | * |
| 43 | * @see java.lang.Thread#run() |
| 44 | */ |
| 45 | public void run() { |
| 46 | // init COM |
| 47 | ComThread.InitSTA(); |
| 48 | if (OnInit()) { |
| 49 | // this call blocks in the win32 message loop |
| 50 | // until quitMessagePump is called |
| 51 | doMessagePump(); |
| 52 | } |
| 53 | OnQuit(); |
| 54 | // uninit COM |
| 55 | ComThread.Release(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Override this method to create and initialize any COM component that you |
| 60 | * want to run in this thread. If anything fails, return false to terminate |
| 61 | * the thread. |
| 62 | * |
| 63 | * @return always returns true |
| 64 | */ |
| 65 | public boolean OnInit() { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Override this method to destroy any resource before the thread exits and |
| 71 | * COM in uninitialized |
| 72 | */ |
| 73 | public void OnQuit() { |
| 74 | // there is nothing to see here |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * calls quitMessagePump |
| 79 | */ |
| 80 | public void quit() { |
| 81 | quitMessagePump(); |
| 82 | } |
| 83 | |
| 84 | /** |
nothing calls this directly
no test coverage detected