Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the help of a fellow developer here, I was able to get the code working as desired. What I needed to do was take everything out of the thread except the call to Initialize(), so that the API instance was not running on a separate thread. I then had a different problem, as the status was set from 2 different threads and was not what I expected it to be when I went to clean up.</p> <p>Here is the final solution:</p> <pre><code>// declare a background worker to init the API private BackgroundWorker _bgWorker; // ctor public HiPathScreenPop( ... ) { ... _phoneListener = new ScreenPopTelephoneListener(); _apiState = ApiState.Allocated; _phoneListener.StatusChanged += new _IScreenPopTelephoneListenerEvents_StatusChangedEventHandler( StatusChangedEvent ); _phoneListener.ScreenPop += new _IScreenPopTelephoneListenerEvents_ScreenPopEventHandler( ScreenPopEvent ); _bgWorker = new BackgroundWorker(); _bgWorker.DoWork += new DoWorkEventHandler(StartInBackground); _bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( bgWorker_RunWorkerCompleted ); _bgWorker.RunWorkerAsync(); } void _bgWorker_DoWork( object sender, DoWorkEventArgs e ) { _phoneListener.Initialize( _strAddress ); } void bgWorker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e ) { _apiState = ApiState.Initialized; // probably not necessary... _phoneListener.StartListening( _intExtension.ToString() ); _apiState = ApiState.Listening; } </code></pre> <p>Now, the API instance is running in the same thread as the UI and everybody's happy. The call to Shutdwn() no longer hangs, I don't need Invoke() for the callbacks, and the long-running code executes in a background worker thread.</p> <p>What this code does not show are the great ideas presented earlier for how to handle the case where the user shuts down before the call to Initialize() returns. The final code will be a synthesis of these solutions.</p> <p>Thanks to all for the great feedback!</p> <p>Dave</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload