• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

About In-Process and Out-Process


Dear exprets ,

Iam working with ActiveX components in visual basic .
The same i raised in VB section also but not yet got any suggessions.
So i posted the same here.
My problem is ,
Iam calling a In-process (Dll) from a client application.
There is big(coded) method in In -process which is executed by client application having reference of this in-process.
Clearly ,The Client is not going to gain the control unless the entire method get executed.
What i decided to do for this, insted calling this big method , if a client call's another method from that in-process component , which host a out-process component and free the client control as soon as out-process is created .
If that out-process component raise an event of this In-process component after some time Interval. We can execute the big processing method without distrubing the client calling this In-Process component.

Experts Please tell me whether is this is possible.
I tried this and got an error as invalid memory reference after it raise the event from In-Process component
Why this error i got.
Hope experts consider this .

regrads
cpearl
0
cpearl_s
Asked:
cpearl_s
  • 4
  • 4
1 Solution
 
cpearl_sAuthor Commented:
Please experts give me reply ASAP
0
 
jhanceCommented:
I think you are confusing the concepts of in-process and out-of-process COM and multi-threading.  

I think a better solution to your problem is to have the existing ActiveX control do its long running function in a thread rather than go through the overhead of changing from in-proc to out-of-proc.
0
 
peterchen092700Commented:
jhance is right, changing the location of the server will not alter it's behavior.

Two ways:
a) (as jhance suggested) the client creates a new thread that runs the activex' operation. All Thread Synchronization, Marshaling etc. is  left to the client

b) The ActiveX control creates it's own thread, and offers a function to "start" the operaiton, a functioon to poll the state, and fires an event if the operation is finished.
All threading issues are left to the activeX (I'd prefer this solution for several reasons - but only if you can change the activex)

Note that the Event *must* be fired from the activex control's main thread


Peter
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
cpearl_sAuthor Commented:
hai jhance and peter,
Yes , i may confused .

Please reconsider this senario.( Actually this is written in VB but I re-structured using C++  )

My In-process (ActiveX Dll)
____________________________________________________
Class Order{
Public:
  LongMethod(){
    <<--- do long process -->>
  }
}
_____________________________________________________

Assume this Class is Created and Deployed as
COM+ Application

Client Application --> Creates a Object Order (COM+)
  set obj = CreateObject("ComPls.Order")

If ClientApplication calls this  LongMethod  
   obj.LongMethod();

Clearly the Client Application won't gain controll back unless and untill that method completes its work.

So , What i thought is, to re-modify the same as.

____________________________________________________
Modified In-process
implement Class Out
Out ObjOut ;
Class Order{
Public:
  StartLongMethod(){
  }
 
  LongMethodCallBack(){
    <<--- do long process -->>
  }
}

 Order::StartLongMethod (){
//Create a Out-Process Component
  set ObjOut=CreateObject("OutProcess")
}
____________________________________________________

As Soon as this is constructed ,a Timer is Executed to make delay automation. After the timer expires this Raise the LongMethodCallBack .(I mean) as soon as out-process is created the client gains the controll back since this is going to be created in seperate thread.
So i designed my Out-Process Component as
____________________________________________________
(ActiveX Exe)
Class Out{
 Out(){
  StartTimer
 }

 TimerCallBack(){
 KillTimer;
 RaiseEvent LongMethodCallBack() ;
 }

 LongMethodCallBack(); // Abstract Method
}
____________________________________________________

When the timer event executed , the outprocess timer destroyes and raise the event LongMethodCallBack of In-Process which executes that longfunctionality.
IF i could able to do this , i can acheive two thing,

1) Client Application is not binded with In-Process untill that long method executes .
2) The Out-Process server the Client Application, from binding .

Please consider and tell what i decided is right or wrong else any other way to do this.

Note : The code is only a Overview on the Logic .Just taket he concept only.

regards
cpearl
0
 
peterchen092700Commented:
a) You don't need an out-of process server for this
In-Process vs. Out-of-Process is only a question of server location, speed and safety. For almost all things legal in COM it doesn't matter if you have a component running inproc or outproc.

b) I'd suggest (simply because I don't know how to do multithreading in VB) to modify the component to use a separate thread for calculation


class Calculator
{
  HRESULT  StartOperation(); // error if already/still running
  BOOL     IsOperationRunning();
  HRESULT  CancelOperation()

  [outgoing event: operation complete]
  Fire_OperationComplete()
};

StartOperation would create a new thread that calls the lengthy operation.

CancelOperation would best set a flag, that is checkked from time to time in the lengthy op thread. It would then use WaitForSingleObject to wait for the thread to terminate.

When the lengthy operation completes, the thread posts a private Windows message (use RegisterMessage) to the ActiveX control's HWND, and terminates

In the ActiveX controls message handler, you can fire the OperationComplete event.

To take care of:
a) Synchronization beetween the threads
b) the lengthy thread MUST NOT do anything with COM (if it needs, you will need to learn a lot more). not calling COM controls, not firing COM events, etc.


Peter
0
 
cpearl_sAuthor Commented:
hai experts ,
many thanks to u and peter.
Peter i got what u tring to say. But the real problem is Visual basic does not support multithreading model, it support only apartment thread model. There my problem started.
Since iam working with VB. That's what i choosen little bit more effort to solve this problem.
Thought iam still in trouble. I did the same logic using..

A Client Application invokes a Out-Process Component in Client System and that is responsible for executing the COM+ (resides in server) object => Client Application is free from Binging with Server Resources(COm+).After it completes the task ,this againg invoke a Event of Caller (  Client Application )which identifies task completed.

But Actuall i thought , this Out-Process should reside inside the server so that instead of ClientAPplication invokes , let COM+ application (DLL's) invoke the same, which reduce the Client System Overheads.

Any how , though i not completely soveld , i patially solved, this with our experts consulting.
Hope i would get more solution iff i dictate the problem in front of some one.
Wishes to u and experts. Thank's to all
regards
cpearl

0
 
peterchen092700Commented:
cpearl:
The whole idea was not to expose the worker thread to COM. The COM threading models alny care about how Interfaces are called from different threads.

0
 
cpearl_sAuthor Commented:
thank's expert
0
 
peterchen092700Commented:
why only C? What was missing?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now