Click here to Skip to main content
15,889,403 members
Home / Discussions / C#
   

C#

 
GeneralRe: code Pin
Blake Coverett28-Oct-03 10:38
Blake Coverett28-Oct-03 10:38 
GeneralRe: code Pin
oOomen28-Oct-03 7:05
oOomen28-Oct-03 7:05 
GeneralFORM SHAPE AND SKIN Pin
_Comet_Keeper_28-Oct-03 3:26
_Comet_Keeper_28-Oct-03 3:26 
GeneralRe: FORM SHAPE AND SKIN Pin
Heath Stewart28-Oct-03 3:34
protectorHeath Stewart28-Oct-03 3:34 
GeneralNew Instance of Internet Explorer Pin
Kenneth Childs28-Oct-03 3:06
Kenneth Childs28-Oct-03 3:06 
GeneralRe: New Instance of Internet Explorer Pin
Heath Stewart28-Oct-03 3:21
protectorHeath Stewart28-Oct-03 3:21 
GeneralAppDomain and singleton pattern Pin
Chris Richner28-Oct-03 0:01
Chris Richner28-Oct-03 0:01 
GeneralRe: AppDomain and singleton pattern Pin
Heath Stewart28-Oct-03 3:17
protectorHeath Stewart28-Oct-03 3:17 
This shouldn't be a problem. Locking against types to create singletons (as is common for determine if an instance already exists) is supposed to be context-bound. Being that the AppDomain is a separate context, this shouldn't pose a problem.

The following code fragment (that works) should prove it:
using System;
using System.IO;
using System.Reflection;

public class Test
{
  public static void Main(string[] args)
  {
    Singleton.SayHello();
    Singleton.SayHello();

  if (!Singleton.Foo)
  {
    Console.WriteLine("Executing entry point in same AppDomain...");
    AppDomain.CurrentDomain.ExecuteAssembly(
      Assembly.GetEntryAssembly().Location);
  }

    if (AppDomain.CurrentDomain.FriendlyName != "New")
    {
      Console.WriteLine("Creating new AppDomain...");

      AppDomain domain = AppDomain.CreateDomain("New",
        AppDomain.CurrentDomain.Evidence);
      domain.ExecuteAssembly(Assembly.GetEntryAssembly().Location);
    }
  }
}

public class Singleton
{
  private TextWriter writer;
  private Singleton()
  {
    Console.WriteLine("Creating new singleton instance...");
    writer = Console.Out;
  }

  private static Singleton instance;
  private static Singleton Instance
  {
    get
    {
      if (instance == null)
        lock (typeof(Singleton))
          if (instance == null)
            instance = new Singleton();
      return instance;
    }
  }

  public static void SayHello()
  {
    Instance.writer.WriteLine("Hello, world!");
  }

  private bool foo = false;
  public static bool Foo // ?
  {
    get
  {
    if (!Instance.foo)
    {
      Instance.foo = true;
      return false;
    }

    return true;
  }
  }
}


 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: AppDomain and singleton pattern Pin
Chris Richner29-Oct-03 5:59
Chris Richner29-Oct-03 5:59 
GeneralRe: AppDomain and singleton pattern Pin
Heath Stewart29-Oct-03 7:54
protectorHeath Stewart29-Oct-03 7:54 
Generalconvert byte array to float data Pin
zecodela27-Oct-03 18:45
zecodela27-Oct-03 18:45 
GeneralRe: convert byte array to float data Pin
Heath Stewart28-Oct-03 2:56
protectorHeath Stewart28-Oct-03 2:56 
QuestionHow to set ACEs on AD classes Pin
Nidhi Narang27-Oct-03 12:41
Nidhi Narang27-Oct-03 12:41 
AnswerRe: How to set ACEs on AD classes Pin
Erick Sgarbi27-Oct-03 13:42
Erick Sgarbi27-Oct-03 13:42 
GeneralRe: How to set ACEs on AD classes Pin
Nidhi Narang28-Oct-03 5:46
Nidhi Narang28-Oct-03 5:46 
QuestionsqlDataReader Thread Safe? Pin
michin127-Oct-03 11:01
michin127-Oct-03 11:01 
GeneralTimeZones in .Net Pin
Vadim Tabakman27-Oct-03 10:41
Vadim Tabakman27-Oct-03 10:41 
GeneralRe: TimeZones in .Net Pin
Heath Stewart27-Oct-03 11:07
protectorHeath Stewart27-Oct-03 11:07 
GeneralRe: TimeZones in .Net Pin
Vadim Tabakman27-Oct-03 11:14
Vadim Tabakman27-Oct-03 11:14 
GeneralRe: TimeZones in .Net Pin
Heath Stewart27-Oct-03 11:17
protectorHeath Stewart27-Oct-03 11:17 
Generalprogress bar to use on .net web client Pin
john51327-Oct-03 8:47
john51327-Oct-03 8:47 
GeneralRe: progress bar to use on .net web client Pin
Heath Stewart27-Oct-03 10:19
protectorHeath Stewart27-Oct-03 10:19 
GeneralArrayList and Binary Search Pin
RB@Emphasys27-Oct-03 8:26
RB@Emphasys27-Oct-03 8:26 
GeneralRe: ArrayList and Binary Search Pin
Heath Stewart27-Oct-03 8:37
protectorHeath Stewart27-Oct-03 8:37 
GeneralRe: ArrayList and Binary Search Pin
RB@Emphasys27-Oct-03 9:05
RB@Emphasys27-Oct-03 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.