Multithreading and AppDomains

dotnet framework

    Sponsored Links

    Next

  • 1. Type is not marked as serializable
    Hi, I have the following C++ code snippet that always give me the error. The type A in Assembly ........... is not marked as serializable when I try to run it. My class already has the [Serializable] attribute. What am I still missing or I am doing something wrong completely? [Serializable] __gc class A { public: A(void); ~A(void); String* S; bool B; void Calc (); Assembly* A; MethodInfo* M; }; void myfunc () { AppDomain* Ad = AppDomain::CreateDomain ("myAd"); A* objA = new A (); Ad->DoCallBack (new CrossAppDomainDelegate (objA, &A::Calc) ); }
  • 2. Returning MarshalByRefObject from an method
    Hi, i'm new to remoting, so perhaps the following question could be stupid or design may be wired. I have a remoting object like this: public class ClientContext : MarshalByRefObject { public UserProfile Profile { get { return ServerContext.CurrentUser.Profile; } } } [Serializable] public class UserProfile { // some properties } As i understand, when calling ClientContext::Profile, this will return a copy of the UserProfile object. The problem with this approach, is that updates on the profile from within client code, dont get puiblished to the server. A behavior i would like to see here. I have tested to make UserProfile class MarshalByRefObject but this returns errors. My question basically is, can this be achieved with remoting, and if so, what approach should i take. I have thought about a CAO version of UserProfile, but this would not completely solve the problem. Because, Profile-Data must be updated server wide. Hope my explanation (my english is bad :)) is ok. Claus

Multithreading and AppDomains

Postby Kai Iske » Sat, 24 Nov 2007 19:41:39 GMT

Hi,

following situation (this is still .NET 1.1 - *sigh*)

For a scheduling application, I create a Thread for every task that is
due to be executed. Once a task execution is due, a running Thread
will be created. The runner thread in turn will instantiate a
TaskRunner object in a new AppDomain, so it is like that. The
TaskRunner then instantiates the Task class and calls a method on an
interface:

1. Create New Thread
2. Thread creates new AppDomain
3. TaskRunner is created in new AppDomain
4. TaskRunner instantiates task class and executes interface method

2. - 4. all happen on the same (newly created thread)

After the TaskRunner has executed the task method, it cleans up,
however when the Thread calls to unload the AppDomain it previously
created, the whole thread is aborted and no code is executed anymore
after the unload.

I don't quite understand why this would happen. My worker thread runs
on the main AppDomain and creates/unloads a child AppDomain. I wonder
why unloading that child AppDomain would kill my worker thread.

Any help would be highly appreciated.

Thanks

Kai

Similar Threads:

1.a better approach to multithreading: Actor Based Multithreading

2.Passing MemoryStream across AppDomains

I'm having trouble determining if/how I can pass a MemoryStream across
AppDomains.  I have a requirement to store files on a share accessible
via a UNC Path, and pull files from, and write to the share.  Another
requirement states that the share has to be accessible to only a single
user, and that the share will sit on a distinct box behind a firewall.

I have a C# assembly that uses System.EnterpriseServices and is
registered as COM+ component that runs under a local user account.  I
have a assembly in the middle that wraps around my COM+ component, and
then a web page that pulls and pushes files.

The COM+ component has a routine to read a file via a FileStream and
returns a MemoryStream.  On the web page side, when I debug, I see that
the actual type of the object returns is a TransparentProxy, which
makes sense, since I am crossing AppDomains.  However, when I try to
use the object, it complains about needing a Registered Channel and
Message Sink.  I'm not terribly familiar with Remoting, though I've
learned a lot more via trial by fire this weekend, and even when I do
register a channel, and use a RealProxy, it bombs.  If I register a
channel and use RegisterWellKnownServerType and
RegisterWellKnownClientType, it still bombs.  If I pass a plain byte[]
out of the COM+ component, all works well.

I do understand that Streams are using pointers under the covers, and
that's likely the source of my errors, but I imagine that someone,
somewhere, has run across this issue before, and I hope that I can get
some help.

More Info:
When using an HttpChannel, and using RegisterWellKnownClientType, I get
a 405 (Method Not Allowed) error and the following stack trace:

Server stack trace:
   at
System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessResponseException(WebException
webException, HttpWebResponse& response)
   at
System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessMessage(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream,
ITransportHeaders& responseHeaders, Stream& responseStream)
   at
System.Runtime.Remoting.Channels.SoapClientFormatterSink.SyncProcessMessage(IMessage
msg)

Exception rethrown at [0]:
   at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
   at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
   at
SC.Platform.FileRepository.ServiceComponent.ServiceComponent.ReadFile(String
filePath)

When using a RealProxy and trying to read the file, I get an
authorization exception:
Access to path xxxx is denied and the following stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String
msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)

I have double-checked, and the COM+ component does have access to the
file AND is running under the correct identity.

Thanks in advance for any help

3.AppDomains and Exceptions

I use application domains to load third party DLL's. Ideally, if one of these 
DLL's throws an exception, I do not want the exception to take down my 
application. It seems that Application Domains are designed to isolate code. 
I have researched quite a bit on this and there does not seem to be a way to 
detect an exception in an app domain and report this error. What I want to do 
is report the error, unload the DLL, then re-load it again. I can detect the 
error with the UnHandledException handler in my main app, but by then its to 
late, my app will then quit. Am I stuck? This is with .NET 2.0.

Thanks,

-Rich

4.Creating and using AppDomains

We are looking at creating an .Net AppDomain and executing specific 
assemblies inside that AppDomain. Where is there documentation or site that 
provides an overview of starting assemblies inside a new AppDomain?

Thanks. 


5.How many AppDomains

6. Serialization w/ AppDomains problem

7. C++ singletons and .NET AppDomains

8. unloading appdomains



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 83 guest