Cross-AppDomain Singleton With Remoting ?
Mar 8, 2011
I have an Addin for MS Excel which needs a singleton to share data amongst modules.Depending on the version of Excel (2003, 2007, 2010), and how Excel was started, it calls my addin from different, unpredictable AppDomains, which prevents the classic singleton approach.Creating a custom AppDomainManager won't work because Excel has already created the AppDomains before the addin is called.
Linking to mscoree to enumerate domains breaks the addin registration process (and I really don't want that anyway); there doesn't seem to be any other way of enumerating, so that isn't an option either.The only solution that I've found is to use remoting. Here's my test rig:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
' Remeber to add reference to System.Runtime.Remoting DLL[code].....
Once everything is running, access to the singleton takes ~100µS, which is perfect. I can live with the ~400mS the first time each AppDomain is initialised. The problem is at startup, where the remoting invocation takes ~2.5 seconds.
View 1 Replies
ADVERTISEMENT
Jun 6, 2011
Explain Singleton architecture of Remoting.
View 1 Replies
May 11, 2011
have created a new AppDomain with a unique name. But i do not want to store that name during the whole application runtime.So i ask you guys if it is possible to get that created AppDomain by name back.
Sub Main()
AppDomain.CreateDomain("TestDomain")
End Sub
so How do i get the AppDomain with the name "TestDomain" back so i can unload it later without storing that AppDomain globally?
View 9 Replies
Jan 19, 2010
What is AppDomain.CreateDomain
View 2 Replies
Dec 2, 2010
I have an ApDomain that is running a Main Routine, for example:
Public Sub Main() Implements Interfaces.IScript.Main
For a as Integer=1 to 99999
[Code]...
View 3 Replies
Apr 28, 2009
Can you have more than one AppDomain in a process Or more than one process in a AppDomain? What about threads? I was always told there were many threads in one process and one processor has many processes. How does App Domains fit into this picture?To me, it seems like its the same concept with a different name??
View 1 Replies
Jun 16, 2007
the forum,this is my first message, and I hope that my English is understandable (I'm Italian)....I've developed a WIndows Service using VB.net 2.0; this service executes a routine every 4 hours... I would like load a dll (without entry point) at run time and when the operation is terminated, I would like unload that. I think that I've to create a new AppDomain and to load my DLL into this, but I don't know the good way to do it.
View 9 Replies
Nov 6, 2009
Sometimes there is a need to initialize the singleton class with some helper values. But we can't "publish" a constructor for it. What is the workaround for this?overloading the GetInstance or setting a color is not my idea. The color should be set only once. I would like to be sure that MyPainter paints ONLY with the initialized color. Any default color should ever be used.
For more clarity I provide a sample:
''' <summary>
''' Singleton class MyPainter
''' </summary>
Public Class MyPainter
[code]....
View 5 Replies
Jul 23, 2010
I am normally a c# programmer but am now working in VB for this one project when I use to set up a singleton class I would follow the Jon Skeet model
public sealed class Singleton
{
static Singleton instance = null;
static readonly object padlock = new object();
[code]....
I get StackTracker.Instance.Instance and it keeps going, while it is not the end of the world it looks bad.is there a way in VB to hide the second instance so the user can not recursively call Instance?
View 1 Replies
Jan 19, 2010
I have recently discovered the singleton approach to mdi child forms and I was trying to integrate this singleton stuff into my "mChildform" class but I keep getting InvalidTypeCastException when I do so. Not sure where I am messing this up.
My mChildform class inherits Form and adds a few properties that are required by all child forms. All of my other project forms inherit this mChildform as their base type instead of form.
When I go directly to one of these forms (the logs form for example) and add
[code...]
I get the exact results that I want. Naturally, since this is something I want all child forms to be able to do I try to add it to my mChildform base class.
The code compiles, but since the reference is of mChildForm type I want to cast it to my usable form class, but it throws the InvalidCastException.
[code..]
I'm not sure why I can't cast it to the other form type, but i'm hoping someone here can explain why I cannot. The Instance() check would always fail if I do not cast my instance to another one of the types.
Since my mChildForm class only holds minimal info to do any real work I have to cast it to the other type. As a workaround I can add the instance method to each new form but I would really like to get it into the base class.
View 5 Replies
Feb 23, 2012
First, I changed my ILS function to be simply: Public Overrides Function InitializeLifetimeService() As Object Return Nothing End Function
Then I included this in my Program as well as A. As Timiz0r pointed out, Form inherits MarshalByRefObject, so I didn't have to include a Inherits statement on my main class (which already inherited Form). This was the big thing, because I didn't include it originally. Next, I changed my AppDomain setup to be:
Dim _ADomain As AppDomain = AppDomain.CreateDomain(Name)
Dim item As New A
item = CType(_ADomain.CreateInstanceAndUnwrap(GetType(A).Assembly.FullName, GetType(A).FullName), A)
With these changes I can now use separate instances of the DLL COM object as desired.
Original Question I am writing an application that creates a list of objects, each referring to a DLL, and each object placed in its own AppDomain to keep the instances of the DLL from interfering with each other. Taken another way:Program maintains a List(Of A)A is created as an instance of AppDomain using CreateInstanceAndUnwrap Each A refers to mirror.dll, which is including in the application's references
[Code]...
View 1 Replies
Aug 16, 2010
I keep getting a "System.Runtime.Serialization.SerializationException" in my application while loading a not-defined assembly (AKA: Plug-in loading.)Even if I turn Serialization on for that plug-in, then it will fail once again. I've been looking around and couldn't find a good tutorial about it..
So all together: How to load an assembly using AppDomain?
View 10 Replies
Apr 23, 2011
I have done a lot of research on the memory leaks present in the WebBrowser control, and the following thread (http:url]...) told me that the only real way to reclaim the memory eaten up by WebBrowser is to load the control in a separate appdomain.I went ahead and did this, but when I unload the AppDomain that the WebbBrowser is created in (using AppDomain.Unload()), the memory is still not freed. I am looking at the Private Bytes of the process in Task Manager (which is accurate and what I'm interested in) to confirm this. The memory usage stays at 50MB+ instead of its default 5MB.Here is my code:
Form1.vb
Imports System.Reflection
Public Class Form1
Private ad_WBInst As AppDomain[code].....
View 6 Replies
Oct 23, 2011
I'm kinda new here, and I didn't know what forum to put this in, so I just put it here. I wanted to load an assembly to an Application Domain, use it, then unload it when I'm done with it. The assembly uses too much memory. The problem is: After I unloaded the assembly, the memory used is not getting freed. I was watching the performance all the time. The available memory increases only after I close the whole application. And that assembly is the only thing that uses a lot of memory in my application. Here's the code I used to load and unload the assembly: How can I free up the memory without closing my application. The memory was suppose to get freed up by simply unloading the assembly that uses it much.
View 2 Replies
Sep 26, 2010
I need to get the information of all the appdomain created in given process?
View 4 Replies
May 17, 2012
Can we configure remoting for the LAN? I studied it halfway but I realised that its for web, but I think it can be possible for LAN too.
View 2 Replies
Apr 5, 2011
I am creating a client/server application that connects via .NET remoting and I'm using TCP. I have 2 config file for client and server. The config file and the server application runs good. But for the client, it runs even though the server is offline and no port is open listening. I've gone through quite a lot of example and don't really know whats happening. This is my client config file.
[Code]...
View 8 Replies
Jan 26, 2009
In the Designer of my forms I usually have this for Singleton purposes.[code]Is there any hack in the IDE that would let me just press a button or something and it will automatically add the code I have above to the selected Designer?I can always type or copy/paste/modify it but I thought there could be something that I could set to just automate this redundant task.
View 7 Replies
Jul 5, 2010
I am working on creating a customized UI composite control. This control would be a container to several other custom controls.As a first step, i am creating the container UI using a singleton pattern. This is because at any point in time only one isntance of this container is allowed to be created. This is fine.Now i want to practice interface based desgin. So i introduced a sinple interface calleD IdesignSurface which has two properties. I would like my singleton class to implement this interface,so i tried something like this and got an error saying "end of line
NotInheritable
Class DesignSurface
implements IDesignSurface
[code]......
View 2 Replies
Oct 16, 2009
Im trying to Implement the Singleton Pattern and im wondering if this is "Thread Safe" or if I am going to have to explicitly perform a SyncLock on the object instance? Example:
Public NotInheritable Class SingleTon
Private Shared _singleton As SingleTon
Private Sub New()
[Code].....
I tried it both ways, using the SyncLock and without, just not sure which one to be using?
View 18 Replies
Sep 8, 2010
I have an web application written in ASP.NET (FW 3.5) (along with some VBScript, this is a legacy app) that uses a utility class in the backend that logs error. I need to log several values that a user has entered in the front-end. Since the utility class has no access to the front end (or any HTTP services), i created a singleton class within the utility namespace that my front end UI can access and store information about the user.
I guess more specifically, I am wondering if there's a way to store session variables that can be shared across the web application and web services through a class referenced by both of the application and web services. For example, I have an error handling class that is used by both instances that required information about the user. Is there a way to create a per-session singleton to hold that information, so that my error class will have access to the user info?
View 1 Replies
Jun 11, 2009
Reading about singletons classes/pattern gave me a pretty good idea for its use. But would it be a good practice to store user related variables in properties of a thread safe singleton class so i can access them by chaining?
Example
When a user logs in several variables will be assigned to a session variable like:
Session("UserID") = reader("UserID")
Session("AccessLevels") = reader("Accesslevels")
Session("UserName") = reader("UserName")
...
Now when working on my webapplication i could always access these values by calling the session() variable, but the chance to forget the session keys or erroneous write them down is significantly. So again would it be good to store these session variables in readonly properties of singleton class so I can access them like:
MySingleton.ID
MySingleton.Accesslevels
MySingleton.UserName
View 4 Replies
Jan 5, 2011
I have a service application that randomly stops without any errors in my log or in the event application log. I believe that there could be an unhandled exception somewhere in the code so I set up the AppDomain.Unhandled event to catch any exceptions. While trying to induce unhandled exceptions I have found that this event is not always fired. I added the following code to my service's Shared Sub Main method (but I orginally had it in the OnStart method and was seeing mostly the same thing)
Dim currentDomain as AppDomain = AppDomain.CurrentDomain
Add Handler currentDomain.UnhandledException, Address of MyHandler
View 7 Replies
Dec 28, 2009
Is it possible to handle exceptions on the AppDomain.CurrentDomain.UnhandledException callback? I want to do the following:Show my own "an exception hasoccured" dialog, with a "Send Report"button After the user dismissed thebox, I want to close my app, but I donot want to Windows default crash dialog "Theapplication needs to close" box toshow up.
View 2 Replies
Nov 8, 2011
I have created an application domain, using which i am executing an .exe file.So the command window does open which has the title as file name. I want to hide the command window.
Dim newAppDomain As AppDomain = AppDomain.CreateDomain("", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation)
newAppDomain.ExecuteAssembly(IO.Path.Combine(Offic eAddInConfig.Instance.BinPath & "Core", "file1.exe"))
Here a command prompt will be opened which need to hide.
View 1 Replies
Jun 22, 2010
how to create a stable plugin architecture. Stable because I plan on opening up plugin creation to the public but I dont want a sloppy coded plugin to take down my whole application.
So I thought of using an AppDomain per plugin and I did a little seaching. But it seems that even using a temp AppDomain to load plugins and then unloading it once all assemblies have been inspected raises complexity allot and I was planing on using an AppDomain per plugin.
I feel the gained stability (if there is any at all) may be raising the complexity so much the app will never be done..
Is there another way to both create a stable application and at the same time making it extensible?
I cases where the host calls a defined function via say IPluginInterface I guess I can pack a whole lot of try catch blocks around that call but what if a plugin insisted of a timed routine that would run continously without being invoked from the host other that a starting call to StartPluginService or something like that?
If I include a plugin like that in the default AppDomain and it blows up I sure will blow my own foot off right?
View 3 Replies
Feb 29, 2012
I currently had a .Net Remoting Application running on Framework 2 under IIS. I have to upgrade it to Framework 4 in order to use some new components. I have been able to set everything up and running smootly on Framework 2, but as soon as I change to Framework 4, I get the following exception when I try to call one of the function of my remote object.
The input stream is not a valid binary format. The starting contents (in bytes) are: 53-79-73-74-65-6D-2E-52-75-6E-74-69-6D-65-2E-52-65
This bug is not the real bug, it is caused by the fact that the remote object is throwing an exception, and IIS wrap the exception in XML, which throws the BinaryFormatter off.See this for more info on the bug.
This is very unfortunate because I cannot see what is causing the exception, and having never used any Remoting before, I do not have much ideas as to where to start debugging. It seems the Exception is thrown before even stepping in the code because I do a fair amount of logging and none of it seems to be triggering.Basically, I'm looking for some clues or pointer from people that encountered similar problems:
What could be causing the exception when no code has changed besides Compiling from .Net 2 to .Net 4?How can I get the full Exception message that is returned?
[Code]...
View 1 Replies
Apr 19, 2009
1)i created remoting server now i want to communicate with that
2)if i want to develop a remoting application how i startadil
View 1 Replies
Oct 1, 2009
I have a server, listening to Remoting request on TCP channel. When first client was connected, it was able to proceed on the lines of code shown in the picture. When a second client connected, it shows this error
View 6 Replies
Jun 27, 2012
So I took this from an example. GetInstance() is called from hundred different places in my program, and when I debug, the line "Prog = New Program" keeps getting hit for each of those calls. Which I thought was exactly what should NOT happen.. Or do I have some fundamental misunderstanding?
[Code]....
It seems the "New" sub triggers a number of calls to Program.GetInstance, before the first one completes. This is due to me earlier having lots of shared public objects in this class, which are no longer shared since the class was made singleton. And these objects, when initialized, calls the Program class for reference to other of it's objects.
View 2 Replies