473,387 Members | 3,781 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,387 software developers and data experts.

What's the right way to do this? (threading/AppDomains)

I need some advice on this. I am working on a fairly complex calculator app
(C#) with lots of functions (and these functions in turn use math functions
from an unmanaged C DLL). A calculation takes a lot of time (up to hours),
and should run on a separate thread from the one that the GUI uses. The GUI
also needs to display various properties for each function (such as
parameters that can be set). It does this with property grid and other grids
(there are lots of functions and some have thousands of properties). The GUI
also needs to display a progress bar, etc. while the calculation is running.

Does it make sense to use two AppDomains? (I'm considering only MBR --
otherwise I don't believe I gain any fault protection.) Will this have any
significant effect on performance? Will the calculator app (server) running
in a 2nd AppDomain perform the same? Will the various property grids
(complex -- with thousands of properties) respond about the same in the GUI?
I'm afraid that updating the GUI as it accesses the calculator functions by
ref across the app domain and then refreshes various large grids will slow
down a lot.

However, I'm in favor of separateAppDomains because the calculator needs to
run on a separate thread and because it relies heavily on unmanaged code. At
the moment, something in this unmanaged code seems to be stepping on memory
the GUI is using. I'm looking for the best way to solve this problem and
isolating the unmanaged code in an AppDomain seems like a good foundation to
start with (as long as the performance will remain acceptable).
Nov 15 '05 #1
4 2933
> Does it make sense to use two AppDomains?

I can't see any benefit for using an AppDomain in this situation.
Multi-threading will handle the UI responsiveness issue with no problems,
and as AppDomains sit in the same process, the C DLL stomping over random
memory is not addressed. AppDomains are only effective at isolating managed
components from each other.

If you can't fix the C DLL memory corruption issue, there isn't much option
but to move the DLL to a separate host process (maybe using
EnterpriseServices), and move the data back to the GUI app using named pipes
or MMFs or remoting.

Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:qdUpb.76576$mZ5.488839@attbi_s54...
I need some advice on this. I am working on a fairly complex calculator app (C#) with lots of functions (and these functions in turn use math functions from an unmanaged C DLL). A calculation takes a lot of time (up to hours),
and should run on a separate thread from the one that the GUI uses. The GUI also needs to display various properties for each function (such as
parameters that can be set). It does this with property grid and other grids (there are lots of functions and some have thousands of properties). The GUI also needs to display a progress bar, etc. while the calculation is running.
Does it make sense to use two AppDomains? (I'm considering only MBR --
otherwise I don't believe I gain any fault protection.) Will this have any
significant effect on performance? Will the calculator app (server) running in a 2nd AppDomain perform the same? Will the various property grids
(complex -- with thousands of properties) respond about the same in the GUI? I'm afraid that updating the GUI as it accesses the calculator functions by ref across the app domain and then refreshes various large grids will slow
down a lot.

However, I'm in favor of separateAppDomains because the calculator needs to run on a separate thread and because it relies heavily on unmanaged code. At the moment, something in this unmanaged code seems to be stepping on memory the GUI is using. I'm looking for the best way to solve this problem and
isolating the unmanaged code in an AppDomain seems like a good foundation to start with (as long as the performance will remain acceptable).

Nov 15 '05 #2
Thank you for your feedback! I was under the mistaken impression that
AppDomains would be effective at isolating the C DLL.

"Nick Wienholt" <go*********@hotmail.com> wrote in message
news:eo****************@TK2MSFTNGP09.phx.gbl...
Does it make sense to use two AppDomains?
I can't see any benefit for using an AppDomain in this situation.
Multi-threading will handle the UI responsiveness issue with no problems,
and as AppDomains sit in the same process, the C DLL stomping over random
memory is not addressed. AppDomains are only effective at isolating

managed components from each other.

If you can't fix the C DLL memory corruption issue, there isn't much option but to move the DLL to a separate host process (maybe using
EnterpriseServices), and move the data back to the GUI app using named pipes or MMFs or remoting.

Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:qdUpb.76576$mZ5.488839@attbi_s54...
I need some advice on this. I am working on a fairly complex calculator app
(C#) with lots of functions (and these functions in turn use math

functions
from an unmanaged C DLL). A calculation takes a lot of time (up to hours), and should run on a separate thread from the one that the GUI uses. The

GUI
also needs to display various properties for each function (such as
parameters that can be set). It does this with property grid and other

grids
(there are lots of functions and some have thousands of properties). The

GUI
also needs to display a progress bar, etc. while the calculation is

running.

Does it make sense to use two AppDomains? (I'm considering only MBR --
otherwise I don't believe I gain any fault protection.) Will this have any significant effect on performance? Will the calculator app (server)

running
in a 2nd AppDomain perform the same? Will the various property grids
(complex -- with thousands of properties) respond about the same in the

GUI?
I'm afraid that updating the GUI as it accesses the calculator functions

by
ref across the app domain and then refreshes various large grids will slow down a lot.

However, I'm in favor of separateAppDomains because the calculator needs

to
run on a separate thread and because it relies heavily on unmanaged

code. At
the moment, something in this unmanaged code seems to be stepping on memory
the GUI is using. I'm looking for the best way to solve this problem and
isolating the unmanaged code in an AppDomain seems like a good

foundation to
start with (as long as the performance will remain acceptable).


Nov 15 '05 #3
While you could do it through app domains, it will add a considerable amount
of complexity to your code. If you were looking for protection from
"misbehaving add-in functions", then I think it would make more sense. I
don't think you would have any performance problems using app domains.

I think the problems you're having now will also show up if you use an app
domain, so my recommendation would be to try to fix that problem instead. If
you post the C headers and the C# code that you're using to call those
functions in the framework, interop group, they should be able to help you
fix your problem. If not, you can ping me at er****@microsoft.com.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:qdUpb.76576$mZ5.488839@attbi_s54...
I need some advice on this. I am working on a fairly complex calculator app (C#) with lots of functions (and these functions in turn use math functions from an unmanaged C DLL). A calculation takes a lot of time (up to hours),
and should run on a separate thread from the one that the GUI uses. The GUI also needs to display various properties for each function (such as
parameters that can be set). It does this with property grid and other grids (there are lots of functions and some have thousands of properties). The GUI also needs to display a progress bar, etc. while the calculation is running.
Does it make sense to use two AppDomains? (I'm considering only MBR --
otherwise I don't believe I gain any fault protection.) Will this have any
significant effect on performance? Will the calculator app (server) running in a 2nd AppDomain perform the same? Will the various property grids
(complex -- with thousands of properties) respond about the same in the GUI? I'm afraid that updating the GUI as it accesses the calculator functions by ref across the app domain and then refreshes various large grids will slow
down a lot.

However, I'm in favor of separateAppDomains because the calculator needs to run on a separate thread and because it relies heavily on unmanaged code. At the moment, something in this unmanaged code seems to be stepping on memory the GUI is using. I'm looking for the best way to solve this problem and
isolating the unmanaged code in an AppDomain seems like a good foundation to start with (as long as the performance will remain acceptable).

Nov 15 '05 #4
I am trying, whenever possible, to post the final conclusions reached in
regard to my initial posts. In this post, my fundamental problem was related
to unmanaged code corrupting memory.

The story probably won't surprise some veterans. I had code (including
unmanaged code) that had been working for over a year. And it had been in
hard use under stressful situations. It never exhibited any problems. I
recently began calling it via an async delegate. We also made a lot of GUI
changes and the exceptions were always happening upon one of several
InitializeComponent method calls completing.

Naturally, the last place I searched for the problem was in the oldest, most
well-tested, unchanged code. However, that is in fact where the problem was.
We had a RCW on an OCX. One of the OCX methods returned an array thru a
short int pointer. The default interop wrapper marshalled this not as an
array, but as a single element. We only used the first element, so it didn't
matter. However, that incorrect parameter marshalling was the root cause of
all the problems -- but it only showed up when we started calling a method
many levels higher via the async delegate.

Anyway, the problem was solved without the use of a 2nd AppDomain.

My experience underscores the advice Willy gave me on another thread
('System.ExecutionEngineException' occurred in Unknown Module):

"'System.ExecutionEngineException' are mostly related to marshaling between
managed and unmanaged code, so maybe you should start to
inspect your PInvoke declarations."

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:qdUpb.76576$mZ5.488839@attbi_s54...
I need some advice on this. I am working on a fairly complex calculator app (C#) with lots of functions (and these functions in turn use math functions from an unmanaged C DLL). A calculation takes a lot of time (up to hours),
and should run on a separate thread from the one that the GUI uses. The GUI also needs to display various properties for each function (such as
parameters that can be set). It does this with property grid and other grids (there are lots of functions and some have thousands of properties). The GUI also needs to display a progress bar, etc. while the calculation is running.
Does it make sense to use two AppDomains? (I'm considering only MBR --
otherwise I don't believe I gain any fault protection.) Will this have any
significant effect on performance? Will the calculator app (server) running in a 2nd AppDomain perform the same? Will the various property grids
(complex -- with thousands of properties) respond about the same in the GUI? I'm afraid that updating the GUI as it accesses the calculator functions by ref across the app domain and then refreshes various large grids will slow
down a lot.

However, I'm in favor of separateAppDomains because the calculator needs to run on a separate thread and because it relies heavily on unmanaged code. At the moment, something in this unmanaged code seems to be stepping on memory the GUI is using. I'm looking for the best way to solve this problem and
isolating the unmanaged code in an AppDomain seems like a good foundation to start with (as long as the performance will remain acceptable).

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daylor | last post by:
hi. i have mult thread vb.net application. it has 30 threads. each thread serves 1 phone caller. the question : is there a reason , to create appdomain for each Phone Service ? meaning 30...
4
by: hazz | last post by:
If I successfully run a VS.NET app which includes the following; ************************** APP 1 **************************** m_iIdnt = new...
9
by: Nadav | last post by:
Hi, I am tring to pass messages between threads, using the good old C++ I would call the GetMessage/PostThreadMessage APIs, Now, I am using C# and i can't find any equivalenty for these calls, any...
13
by: Mark | last post by:
Hi, Normally in what kind of situation system will abort a thread created manually ? And how do I know the thread is aborted by system after I start it? Thanks! Mark
8
by: ecir.hana | last post by:
Dear list, maybe I'm overlooking something obvious or this is not possible at all or I don't know. Please, consider the following code: ## insert here anything you like def changer():
10
by: rh0dium | last post by:
Hi all, Below is a basic threading program. The basic I idea is that I have a function which needs to be run using a queue of data. Early on I specified my function needed to only accept basic...
0
by: aghalnan | last post by:
In doing some research it is said that a singleton is bounded to the appdomain that created it. But im experiencing and issue where my singleton is crossing appdomains. Now both my appDomains are...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: PRR | last post by:
Here is a code i found on "how to enumerate appdomains in a current process". The original code was posted by Thomas Scheidegger Add the following as a COM reference -...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.