MultiThreading ActiveX DLL调用... [英] MultiThreading an ActiveX DLL call...

查看:78
本文介绍了MultiThreading ActiveX DLL调用...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


有没有一种很好的方法可以通过一个线程从一个

ActiveX DLL(内部)调用一个很大的时间消耗函数而不会阻塞主用户界面?


以下是详细信息:


我有一个CInteropCall类封装了对visual basic的调用

ActiveX DLL函数名为FillAlloc_ArrayStruct_Double(),它是分配一个大的结构数组,使用内循环填充它

(对于i = 1到300000 .. 。)


我通过主UI中的一个帖子调用这个BigProcess

像这样:


CInteropCall MyThreadProcess = new CInteropCall();

Thread m_WorkerThread;

m_WorkerThread = new Thread(new ThreadStart(MyThreadProcess.TestMe));

m_WorkerThread.IsBackground = true;

m_WorkerThread.Name =" ThreadLow";

m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;

m_WorkerThread.Start();

这是来自CInteropCall类的TestMe()方法,该方法通过VB6类的实例调用

函数:

public void TestMe( )

{

AX_DLL.FillAlloc_ArrayStruct_Double(3000000,ref array_struct_double);

}

问题是:

主线UI在启动线程时被阻止,并且在线程执行期间不时



测试解决方案:

- 在vb6函数的内部循环中添加Sleep(1)

它不会改变很多

- 添加DoEvents( )在vb6函数中

它不会改变很多但会减慢线程执行速度。

从ac#函数执行的同一个大循环不会阻塞主要的

用户界面(即使没有睡眠(1)...),用户界面仍然非常流畅。

任何想法让一个内置的vb6 activex调用''UI线程友好''?

(或者也许没办法......)


问候,

Cyber​​tof。

Hello,

Is there a good way to call a big time-consumming function from an
ActiveX DLL (interoped) through a thread without blocking the main UI ?

Here are the details :

I have a class CInteropCall encapsulating a call to a visual basic
ActiveX DLL function named FillAlloc_ArrayStruct_Double(), which is
allocating a big struct array an fills it using a inner loop
(for i = 1 to 300000...)

I''m calling this BigProcess through a thread from the main UI
like this :

CInteropCall MyThreadProcess = new CInteropCall();
Thread m_WorkerThread;
m_WorkerThread = new Thread(new ThreadStart(MyThreadProcess.TestMe));
m_WorkerThread.IsBackground = true;
m_WorkerThread.Name = "ThreadLow";
m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;
m_WorkerThread.Start();
Here is the TestMe() method from the CInteropCall class which is calling
the function through an instance of a VB6 Class :
public void TestMe()
{
AX_DLL.FillAlloc_ArrayStruct_Double(3000000, ref array_struct_double);
}
The problem is :
The main UI is blocked when starting the thread, and from time to time
during the thread execution.

Solutions tested :
- adding a Sleep(1) in the inner loop of the vb6 function
It does not change a lot
- adding a DoEvents() in the vb6 function
It does not change a lot but slows down the thread execution.
The same big loop executing from a c# function does not block the main
UI (even without sleep(1)...), the UI remains very smooth.
Any idea to make an interoped vb6 activex call ''UI thread friendly'' ?
(or maybe there is no way to do it...)

Regards,
Cybertof.

推荐答案



" ; Cyber​​tof" < CY ************ @ ifrance.com>在留言中写道

新闻:MP ************************ @ news.wanadoo.fr ...

"Cybertof" <cy************@ifrance.com> wrote in message
news:MP************************@news.wanadoo.fr...
你好,

有没有一种很好的方法可以通过一个线程从一个
ActiveX DLL(内部)调用一个大的时间消耗函数而不会阻塞主UI?

以下是详细信息:

我有一个类CInteropCall封装了一个名为FillAlloc_ArrayStruct_Double()的可视化基本的ActiveX DLL函数的调用,即
分配一个大的结构数组,使用内循环填充它(对于i = 1到300000 ...)

我正在通过主UI的线程调用这个BigProcess像这样:

CInteropCall MyThreadProcess = new CInteropCall();
线程m_WorkerThread;
m_WorkerThread =新线程(新的ThreadStart(MyThreadProcess.TestMe));
m_WorkerThread.IsBackground = true;
m_WorkerThread.Name =" ThreadLow";
m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;
m_W orkerThread.Start();

这是来自CInteropCall类的TestMe()方法,它通过VB6类的实例调用
函数:
public void TestMe( )
{
AX_DLL.FillAlloc_ArrayStruct_Double(3000000,ref array_struct_double);
}

问题是:
启动线程时主UI被阻止在线程执行期间不时


测试的解决方案:
- 在vb6函数的内部循环中添加Sleep(1)
它不会改变很多
- 在vb6函数中添加DoEvents()
它不会改变很多但会减慢线程执行速度。

从同一个大循环执行ac#功能不会阻止主UI(即使没有睡眠(1)...),UI仍然非常流畅。

任何想法进行内置vb6 activex调用'' UI线程友好''?
(或许没有办法做到这一点......)

问候,
Cyber​​tof。
Hello,

Is there a good way to call a big time-consumming function from an
ActiveX DLL (interoped) through a thread without blocking the main UI ?

Here are the details :

I have a class CInteropCall encapsulating a call to a visual basic
ActiveX DLL function named FillAlloc_ArrayStruct_Double(), which is
allocating a big struct array an fills it using a inner loop
(for i = 1 to 300000...)

I''m calling this BigProcess through a thread from the main UI
like this :

CInteropCall MyThreadProcess = new CInteropCall();
Thread m_WorkerThread;
m_WorkerThread = new Thread(new ThreadStart(MyThreadProcess.TestMe));
m_WorkerThread.IsBackground = true;
m_WorkerThread.Name = "ThreadLow";
m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;
m_WorkerThread.Start();
Here is the TestMe() method from the CInteropCall class which is calling
the function through an instance of a VB6 Class :
public void TestMe()
{
AX_DLL.FillAlloc_ArrayStruct_Double(3000000, ref array_struct_double);
}
The problem is :
The main UI is blocked when starting the thread, and from time to time
during the thread execution.

Solutions tested :
- adding a Sleep(1) in the inner loop of the vb6 function
It does not change a lot
- adding a DoEvents() in the vb6 function
It does not change a lot but slows down the thread execution.
The same big loop executing from a c# function does not block the main
UI (even without sleep(1)...), the UI remains very smooth.
Any idea to make an interoped vb6 activex call ''UI thread friendly'' ?
(or maybe there is no way to do it...)

Regards,
Cybertof.




您应该初始化(m_WorkerThread)线程以进入STA。你现在这样做的方式导致你的COM对象在主UI线程上运行。


...

m_WorkerThread.ApartmentState = ApartmentState.STA;

m_WorkerThread.Start();

....


Willy。



You should initialize your (m_WorkerThread) thread to enter an STA. The way
you do it now results in your COM object to run on the main UI thread.

...
m_WorkerThread.ApartmentState = ApartmentState.STA;
m_WorkerThread.Start();
....

Willy.


在文章< ej ************* @ TK2MSFTNGP10.phx.gbl>中,
wi ************* @ telenet.be 说......
In article <ej*************@TK2MSFTNGP10.phx.gbl>,
wi*************@telenet.be says...

您应该初始化(m_WorkerThread)线程以进入STA。你现在这样做的方式导致你的COM对象在主UI线程上运行。
..
m_WorkerThread.ApartmentState = ApartmentState.STA;
m_WorkerThread.Start();
...
You should initialize your (m_WorkerThread) thread to enter an STA. The way
you do it now results in your COM object to run on the main UI thread. ..
m_WorkerThread.ApartmentState = ApartmentState.STA;
m_WorkerThread.Start();
...



嗨威利,


这正是我不想要的......

我希望线程不会打扰主UI线程。

Cyber​​tof。


Hi Willy,

That''s exactly what I do not want...
I want the thread no to disturb the main UI thread at all.
Cybertof.




" Cyber​​tof" < CY ************ @ ifrance.com>在留言中写道

新闻:MP ************************ @ news.wanadoo.fr ...

"Cybertof" <cy************@ifrance.com> wrote in message
news:MP************************@news.wanadoo.fr...
文章< ej ************* @ TK2MSFTNGP10.phx.gbl>,
wi ************* @ telenet.be 说...
In article <ej*************@TK2MSFTNGP10.phx.gbl>,
wi*************@telenet.be says...



我希望线程没有打扰主UI线程。


I want the thread no to disturb the main UI thread at all.



当然,但你不要通过不初始化后台线程来打扰UI br />
输入一个STA,注意这不是UI线程的公寓,而是一个新创建的

公寓。

如果你不是初始化你的背景线程进入STA,AX对象

将进入UI线程的公寓并调用此对象上的方法

将在UI线程上运行。


希望现在很清楚。


威利。


Sure, but YOU DO disturb the UI by NOT initializing the background thread to
enter an STA, note this is not the UI thread''s apartment but a newly created
apartment.
If you don''t initialize your backround thread to enter an STA, the AX object
will enter the UI thread''s apartment and calls to methods on this object
will run on the UI thread.

Hope it''s clear now.

Willy.

这篇关于MultiThreading ActiveX DLL调用...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆