By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,666 Members | 1,544 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,666 IT Pros & Developers. It's quick & easy.

async call to ActiveX is still blocking UI

P: n/a
Hello

I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking.

If i put the thread to sleep in my delegate call, the application is well behaved (no UI freeze), but the call to the com object causes the UI to lock up

Do I have to manage calls to an ActiveX object differently than using the BeginInvoke and a callback

A sample of the code I am using
/// <summary
// Connect to the devic
/// </summary
/// <returns></returns
public bool BeginConnect(

bool bRetVal = false
IAsyncResult ar
int threadId

// Create the delegate
AsyncDelegate dlgt = new AsyncDelegate(m_ad.AutoConnect)

threadId = AppDomain.GetCurrentThreadId()
Console.WriteLine("In BeginConnect Calling BeginInvoke from {0}.", threadId)

// Initiate the asychronous call. Include an AsyncCallbac
// delegate representing the callback method, and the dat
// needed to call EndInvoke
ar = dlgt.BeginInvoke( out threadId, new AsyncCallback(AutoConnectCallback), dlgt )

bRetVal = ar.IsCompleted

return bRetVal

public int AutoConnect(out int threadId)

int ret = 0
Console.WriteLine("Begin Call to: AutoConnect.")

threadId = AppDomain.GetCurrentThreadId()

// ActiveX call that blocks
m_driver.AutoConnect()

Console.WriteLine("End Call to: AutoConnect.")
return ret
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Using asynch callbacks won't help, probably your activeX object lives on the
UI thread, and the calls are made from the threadpool thread, which is bad
for a number of reasons
- Your set-up requires apartment marshaling - threadpool threads are MTA
while UI thread is STA, and can be a source of numerous threading problems
and perf degradation.
- You will still block the UI while running activeX methods.

What you should do instead of using asynch delegates is create a separate
thread initialized for STA, create an instance of your activeX object and
call his methods on that same thread. Note that if you need to access the UI
thread from this thread, you need to call Control.Invoke or
Control.BeginInvoke.

Willy.
"Marwan" <an*******@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
Hello,

I am using asynchronous delegates to make a call to a COM ActiveX object,
but even though the call occurs on a separate thread, my UI is still
blocking.

If i put the thread to sleep in my delegate call, the application is well
behaved (no UI freeze), but the call to the com object causes the UI to
lock up.

Do I have to manage calls to an ActiveX object differently than using the
BeginInvoke and a callback?

A sample of the code I am using:
/// <summary>
// Connect to the device
/// </summary>
/// <returns></returns>
public bool BeginConnect()
{
bool bRetVal = false;
IAsyncResult ar;
int threadId;

// Create the delegate.
AsyncDelegate dlgt = new AsyncDelegate(m_ad.AutoConnect);

threadId = AppDomain.GetCurrentThreadId();
Console.WriteLine("In BeginConnect Calling BeginInvoke from {0}.",
threadId);

// Initiate the asychronous call. Include an AsyncCallback
// delegate representing the callback method, and the data
// needed to call EndInvoke.
ar = dlgt.BeginInvoke( out threadId, new
AsyncCallback(AutoConnectCallback), dlgt );

bRetVal = ar.IsCompleted;

return bRetVal;
}

public int AutoConnect(out int threadId)
{
int ret = 0;
Console.WriteLine("Begin Call to: AutoConnect.");

threadId = AppDomain.GetCurrentThreadId();

// ActiveX call that blocks!
m_driver.AutoConnect();

Console.WriteLine("End Call to: AutoConnect.");
return ret;
}

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.