Exemplo n.º 1
0
 public static bool CPlApplet()
 {
     Thing0.Exec();
     return(true);
 }
Exemplo n.º 2
0
 [ComUnregisterFunction] //This executes if registration fails
 public static void UnRegisterClass(string key)
 {
     Console.WriteLine("I shouldn't really execute either.");
     Thing0.Exec();
 }
Exemplo n.º 3
0
 public void Exec()
 {
     Thing0.Exec();
 }
Exemplo n.º 4
0
 public static void Main()
 {
     Console.WriteLine("Hello From Main...I Don't Do Anything");
     Thing0.Exec();
     //Add any behaviour here to throw off sandbox execution/analysts :)
 }
Exemplo n.º 5
0
 //The Methods can be Uninstall/Install.  Install is transactional, and really unnecessary.
 public override void Uninstall(System.Collections.IDictionary savedState)
 {
     Console.WriteLine("Hello There From Uninstall");
     Thing0.Exec();
 }
Exemplo n.º 6
0
 [ComUnregisterFunction] //This executes if registration fails
 public static void UnRegisterClass(string key)
 {
     Thing0.Exec();
 }
Exemplo n.º 7
0
    public static void DllInstall(bool bInstall, IntPtr a)
    {
        string b = Marshal.PtrToStringUni(a);

        Thing0.ExecParam(b);
    }
Exemplo n.º 8
0
 public static void EntryPoint(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow)
 {
     Thing0.Exec();
 }
Exemplo n.º 9
0
 public static bool InitializePrintMonitor2()
 {
     Thing0.Exec();
     return(true);
 }
Exemplo n.º 10
0
 public static bool InitHelperDll()
 {
     Thing0.Exec();
     return(true);
 }
Exemplo n.º 11
0
 public static void DllUnregisterServer()
 {
     Thing0.Exec();
 }
Exemplo n.º 12
0
 public static bool DllUnregisterServer()
 {
     Thing0.ExecParam("DllUnregisterServer");
     return(true);
 }
Exemplo n.º 13
0
 public void Exec()
 {
     Thing0.ExecParam("COM Public Exec");
 }
Exemplo n.º 14
0
 [ComRegisterFunction] //This executes if registration is successful
 public static void RegisterClass(string key)
 {
     Console.WriteLine("I shouldn't really execute");
     Thing0.ExecParam("COM UnRegisterClass");
 }
        public async Task GetRequiredService_UsesSingletonAndLazyLocks_NoDeadlock()
        {
            using (var mreForThread1 = new ManualResetEvent(false))
                using (var mreForThread2 = new ManualResetEvent(false))
                {
                    // Thread 1: Thing1 (transient) -> Thing0 (singleton)
                    // Thread 2: Thing2 (singleton) -> Thing1 (transient) -> Thing0 (singleton)

                    // 1. Thread 1 resolves the Thing1 which is a transient service
                    // 2. In parallel, Thread 2 resolves Thing2 which is a singleton
                    // 3. Thread 1 enters the factory callback for Thing1 and takes the lazy lock
                    // 4. Thread 2 takes callsite for Thing2 as a singleton lock when it resolves Thing2
                    // 5. Thread 2 enters the factory callback for Thing1 and waits on the lazy lock
                    // 6. Thread 1 calls GetRequiredService<Thing0> on the service provider, takes callsite for Thing0 causing no deadlock
                    // (rather than taking the locks that are already taken - either the lazy lock or the Thing2 callsite lock)

                    Thing0           thing0 = null;
                    Thing1           thing1 = null;
                    Thing2           thing2 = null;
                    IServiceProvider sp     = null;
                    var sb = new StringBuilder();

                    // Arrange
                    var services = new ServiceCollection();

                    var lazy = new Lazy <Thing1>(() =>
                    {
                        sb.Append("3");
                        mreForThread2.Set(); // Now that thread 1 holds lazy lock, allow thread 2 to continue

                        // by this time, Thread 2 is holding a singleton lock for Thing2,
                        // and Thread one holds the lazy lock
                        // the call below to resolve Thing0 does not hang
                        // since singletons do not share the same lock upon resolve anymore.
                        thing0 = sp.GetRequiredService <Thing0>();
                        return(new Thing1(thing0));
                    });

                    services.AddSingleton <Thing0>();
                    services.AddTransient(sp =>
                    {
                        if (ThreadId == 2)
                        {
                            sb.Append("1");
                            mreForThread1.Set();     // [b] Allow thread 1 to continue execution and take the lazy lock
                            mreForThread2.WaitOne(); // [c] Wait until thread 1 takes the lazy lock

                            sb.Append("4");
                        }

                        // Let Thread 1 over take Thread 2
                        Thing1 value = lazy.Value;
                        return(value);
                    });
                    services.AddSingleton <Thing2>();

                    sp = services.BuildServiceProvider();

                    var t1 = Task.Run(() =>
                    {
                        ThreadId         = 1;
                        using var scope1 = sp.CreateScope();
                        mreForThread1.WaitOne(); // [a] Waits until thread 2 reaches the transient call to ensure it holds Thing2 singleton lock

                        sb.Append("2");
                        thing1 = scope1.ServiceProvider.GetRequiredService <Thing1>();
                    });

                    var t2 = Task.Run(() =>
                    {
                        ThreadId         = 2;
                        using var scope2 = sp.CreateScope();
                        thing2           = scope2.ServiceProvider.GetRequiredService <Thing2>();
                    });

                    // Act
                    await t1;
                    await t2;

                    // Assert
                    Assert.NotNull(thing0);
                    Assert.NotNull(thing1);
                    Assert.NotNull(thing2);
                    Assert.Equal("1234", sb.ToString()); // Expected order of execution
                }
        }
Exemplo n.º 16
0
 public static bool DllUUnregisterServer()
 {
     Thing0.Exec();
     return(true);
 }
 public Thing1(Thing0 thing0)
 {
 }
Exemplo n.º 18
0
 //The Methods can be Uninstall/Install.  Install is transactional, and really unnecessary.
 public override void Uninstall(System.Collections.IDictionary savedState)
 {
     Thing0.Exec();
 }