Object pooling services can reduce the overhead of creating each object from scratch. When an object is activated, it is extracted from the pool. When you deactivate an object, it is put back in the pool, waiting for the next request.
Let's take a look at how to deal with object pooling in the main thread:
static void Main (string[] args) {instancepoolresolver.register<orderqueryserviceinterface, Orderq
Ueryservice> ();
while (true) {Thread.Sleep (2000);
Console.clear (); for (int i = 0; i < 20;i++) {ThreadPool.QueueUserWorkItem (new WaitCallback) (consum
Eobject)); }} private static void Consumeobject (object state) {Orderqueryser
Viceinterface srv = null; The try {using (SRV = instancepoolresolver.resolve<orderqueryserviceinterface> ())//is fetched from the object pool Object, there is no available object then throw exception {Console.WriteLine ("Object ID--->" + srv.
GetHashCode ()); Thread.Sleep (1000); Intentionally long time consuming object} catch (Exception ex) {Console.writeli NE (ex. MEssage); finally {if (SRV!= null) srv.
Dispose (); }
}
Operation Effect: