469,610 Members | 1,859 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

async call to ActiveX is still blocking UI

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
1 3086
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.

Similar topics

6 posts views Thread by Vanessa | last post: by
2 posts views Thread by Tom Vandeplas | last post: by
6 posts views Thread by Shak | last post: by
11 posts views Thread by atlaste | last post: by
10 posts views Thread by ColoradoGeiger | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.