Ho can I break up a dll into smaller chunks

  • Thread starter Thread starter d_well
  • Start date Start date
D

d_well

Hi,

I use a method of a dll and this method use 3 or 4 seconds to
calculate a result. This method run into a thread. I noticed when I am
runing this method, the other thread cannot be run as long as this
method isn't finished. So the other threads don't run until the method
of the dll is finished, so during this time all my application is
suspended, it is my problem, all my application must be running when
the calculation thread is running.
Is this problem normal? Is there a manner to break up the dll's method
into smaller chunks or something like this to share cpu time with
other threads in my application?

Thanks for an answer.

Fabien Pochon
 
d_well said:
Hi,

I use a method of a dll and this method use 3 or 4 seconds to
calculate a result. This method run into a thread. I noticed when I am
runing this method, the other thread cannot be run as long as this
method isn't finished. So the other threads don't run until the method
of the dll is finished, so during this time all my application is
suspended, it is my problem, all my application must be running when
the calculation thread is running.
Is this problem normal? Is there a manner to break up the dll's method
into smaller chunks or something like this to share cpu time with
other threads in my application?

Thanks for an answer.

Fabien Pochon

As I told you in another thread, you'll should call Sleep at regular
intervals during execution of the method, this way you give the other
thread(s) some time to run.
Mind to post the calc method?

Willy.
 
Willy Denoyette said:
As I told you in another thread, you'll should call Sleep at regular
intervals during execution of the method, this way you give the other
thread(s) some time to run.
Mind to post the calc method?

Willy.

It doesn't work because I can't call Sleep during the execution of the
method. During the execution of the method nothing else can be done
before the method return a result and I can't insert Sleep in the
method because it is a dll. I tried to change the ThreadPriority but
nothing change, the dll's method use all the ressources of my process
and blocks the other threads. I have to run my others thread more once
by returned result.
It is stange that I can't execute nothing else during the execution of
the method of the dll.

Fabien Pochon
 
d_well said:
It doesn't work because I can't call Sleep during the execution of the
method. During the execution of the method nothing else can be done
before the method return a result and I can't insert Sleep in the
method because it is a dll. I tried to change the ThreadPriority but
nothing change, the dll's method use all the ressources of my process
and blocks the other threads. I have to run my others thread more once
by returned result.
It is stange that I can't execute nothing else during the execution of
the method of the dll.

Fabien Pochon

What I meant was to insert Sleep() calls IN the calculation method, sure, if
you don't have the source code of the method you are calling you are stuck.
If you are running this on is a single CPU machine and the calculation
method only executes CPU instructions before retuning a result, other
threads have a little chance to get the CPU to run.
I'm still not clear what you expect to do in the other thread(s), can you
describe your scenario a bit more in detail?

Willy.
 
Willy Denoyette said:
What I meant was to insert Sleep() calls IN the calculation method, sure, if
you don't have the source code of the method you are calling you are stuck.
If you are running this on is a single CPU machine and the calculation
method only executes CPU instructions before retuning a result, other
threads have a little chance to get the CPU to run.
I'm still not clear what you expect to do in the other thread(s), can you
describe your scenario a bit more in detail?

Willy.


Hi,

I think I found the solution for my problem. I changed the COM
threading for my application, it was [STAThread] and I changed to
[MTAThread]. Now the calculation thread doesn't disturb the other
threads. Can you answer me if this solution is good or not?

Thanks.

Fabien
 
d_well said:
Hi,

I think I found the solution for my problem. I changed the COM
threading for my application, it was [STAThread] and I changed to
[MTAThread]. Now the calculation thread doesn't disturb the other
threads. Can you answer me if this solution is good or not?

Thanks.

Fabien

Well it's the first time you talk about COM, you should have mentioned that
before, that's why I asked about the context you are running in.
If your application is a windows application you must keep the STAThread
attribute set.
If your COM object needs a STA to run in, and I guess it is, you have to
initialize your background thread to enter a STA by setting the thread's
ApartmentState property to STA, like this...
someThread.ApartmentState = ApartmentState.STA;
,before you start the thread.
Note that you better call the COM methods only from this thread, this to
prevent inter-thread marshaling overhead.

Willy.
 
Willy Denoyette said:
What I meant was to insert Sleep() calls IN the calculation method, sure, if
you don't have the source code of the method you are calling you are stuck.
If you are running this on is a single CPU machine and the calculation
method only executes CPU instructions before retuning a result, other
threads have a little chance to get the CPU to run.
I'm still not clear what you expect to do in the other thread(s), can you
describe your scenario a bit more in detail?

Willy.


Hi,

I think I found the solution for my problem. I changed the COM
threading for my application, it was [STAThread] and I changed to
[MTAThread]. Now the calculation thread doesn't disturb the other
threads. Can you answer me if this solution is good or not?

Thanks.

Fabien
 
Back
Top