473,791 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 separateAppDoma ins 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 2954
> 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
EnterpriseServi ces), 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.7657 6$mZ5.488839@at tbi_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 separateAppDoma ins 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*********@ho tmail.com> wrote in message
news:eo******** ********@TK2MSF TNGP09.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
EnterpriseServi ces), 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.7657 6$mZ5.488839@at tbi_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 separateAppDoma ins 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
"misbehavin g 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****@microsof t.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.7657 6$mZ5.488839@at tbi_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 separateAppDoma ins 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
InitializeCompo nent 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.Execut ionEngineExcept ion' occurred in Unknown Module):

"'System.Execut ionEngineExcept ion' 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.7657 6$mZ5.488839@at tbi_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 separateAppDoma ins 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
1924
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 appdomains ? or , the purpose for creating another appdomains, is diffrent ?
4
2939
by: hazz | last post by:
If I successfully run a VS.NET app which includes the following; ************************** APP 1 **************************** m_iIdnt = new System.Security.Principal.GenericIdentity(t.UserName,"MyAuthentication"); //user and My authentication type added to Identity string roles = {"Chief Cook and Bottle Washer", "Master Gardener"};
9
13462
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 Idea how to communicate between threads and access the threads message queue will be appriciated... -- Nadav http://www.ddevel.com
13
730
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
1894
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
1598
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 parameters ( no postional *args or *kwargs ) but now I am re-writing it and I want to accept these. Is there anyway to determine what parameters are needed by a given function and format the arguments given appropriately. My problem is that I...
0
1100
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 created and load completly different assemblies in them and run their interface. But they both inherit the another assembly which contains a singleton object. So im just wondering that since both of these dlls that are loaded into seperate...
4
4531
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 child apps of an IIS application and can be used by multiple users during the application life cycle and for multiple page loads for the same or different page under a root application. What I don't understand and need to know is whether that...
0
8730
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 - ~\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscoree.tlb using mscoree; using System.Runtime.InteropServices;
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.