473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 3351
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing...
2
by: Tom Vandeplas | last post by:
Hi all, When using an asynchronous API call (in my case WriteFileEx) in a thread it seems to become blocking instead of non-blocking (see details below). Can somebody explain me what is...
11
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
1
by: Marwan | last post by:
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...
10
by: Brian Parker | last post by:
I inherited a C++ DLL that I need to remotely call multiple times asynchronously. What I have developed is: CSharp web application that makes asynchronous calls to a CSharp Web Service. The...
6
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
10
by: ColoradoGeiger | last post by:
I have a fairly standard server application that I am using asynchronous socket calls to make connections, send and receive data, and all of that jazz. No blocking methods was my goal in writing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.